Tuesday, May 11, 2021

#1 2021-04-17 04:35:54 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 707

NSExpression's expressionWithFormat

UPDATE: This handler value should be doubleValue() so I have correct that.

Applescript:

set theValue to my expressionWithFormat:"add:to:(10,50)"
on expressionWithFormat:theExpression
   return ((current application's NSExpression's expressionWithFormat:theExpression)'s expressionValueWithObject:(missing value) context:(missing value))'s doubleValue()
end expressionWithFormat:

Last edited by Fredrik71 (2021-04-27 04:57:07 am)


if you are the expert, who will you call if its not your imagination.

Offline

 

#2 2021-04-27 01:00:24 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1797

Re: NSExpression's expressionWithFormat

To get the expression representation you should not ask for its value:

Applescript:


use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set theExpession to current application's NSExpression's expressionWithFormat:"add:to:(10,50)"
log (theExpession)

--> RESULT: "(NSFunctionExpression) 10 + 50"


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2021-04-27 05:04:06 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 707

Re: NSExpression's expressionWithFormat

KniazidisR wrote:

To get the expression representation you should not ask for its value:


Its was the value I was interesting in and on my machine I got the right result in log but
not as result. That why I created this topic in the first place. The solution was to restart my computer and everything is correct.

I guess Apple Events or communication to it could hang. The strange thing was that the log worked.
It have never happen to me before.


if you are the expert, who will you call if its not your imagination.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)