Friday, June 23, 2017

#1 2017-06-06 11:27:35 am

xmaslance
Member
Registered: 2017-04-05
Posts: 15

POSIX file Returning scpt Object

I'm baffled about some code that works fine in Script Debugger but fails when run within an ASOC app.

When the following is run in Xcode, the "POSIX file" assignment returns a 'scpt' object instead of 'furl'.

Applescript:


set x to POSIX file "/"
log class of x
-- <NSAppleEventDescriptor: 'scpt'>
log x
-- <AppDelegate @0x608000225f20: OSAID(4) ComponentInstance(0x810000)>

log class of (POSIX file "/")
-- <NSAppleEventDescriptor: 'furl'>
log (POSIX file "/") as string
-- Can’t make «script» into type string. (error -1700)

In Script Debugger I get what I would expect:

Applescript:


set x to POSIX file "/"
log class of x
-- <<class furl>>
log x
-- "Macintosh:HD"

log class of (POSIX file "/")
-- <<class furl>>
log (POSIX file "/") as string
-- "Macintosh:HD"

What's going on here?

Thanks,
Lance

Offline

 

#2 2017-06-06 11:31:04 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11448
Website

Re: POSIX file Returning scpt Object

In AppleScriptObjC you have to write

Applescript:

set x to "/" as POSIX file

POSIX file x does not work


regards

Stefan

Offline

 

#3 2017-06-06 11:46:17 am

xmaslance
Member
Registered: 2017-04-05
Posts: 15

Re: POSIX file Returning scpt Object

Ah, researching that further, it's the difference between "coercion" versus an "object specifier". A subtle but important concept I have yet to learn!

Frustrating the developer docs don't mention the "as POSIX file" notation.

https://developer.apple.com/library/con … lders.html

Thanks!

Offline

 

#4 2017-06-06 12:39:31 pm

xmaslance
Member
Registered: 2017-04-05
Posts: 15

Re: POSIX file Returning scpt Object

PS. Any insight as to why the execution environment of Xcode behaves so different from Script Debugger in this case?

Offline

 

#5 2017-06-06 01:13:39 pm

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11448
Website

Re: POSIX file Returning scpt Object

Simply spoken

– The ScriptDebugger environment is AppleScript.
– The Xcode environment is Objective-C bridged to AppleScript.


regards

Stefan

Offline

 

#6 2017-06-06 08:16:32 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 5022

Re: POSIX file Returning scpt Object

Further to Stefan's answer:

AppleScript's log command does nothing itself. What you see logged in Script Debugger or Script Editor is produced by the editor itself, which retrieves a "human readable" form of the AppleScript object in question.

In Xcode, log takes advantage of the normal NSLog-style logging system, which requires Cocoa objects, so AppleScript objects first have to be converted to Cocoa equivalents.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#7 2017-06-06 08:29:27 pm

xmaslance
Member
Registered: 2017-04-05
Posts: 15

Re: POSIX file Returning scpt Object

Thanks for the clarification. I just equated 'log' to doing a 'printf' but was always curious why Script Debugger output is not formatted as just a series of log lines. Now I know it's because SD is free to do it's own thing with log statements!

Offline

 

#8 2017-06-07 04:39:46 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2648

Re: POSIX file Returning scpt Object

xmaslance wrote:

PS. Any insight as to why the execution environment of Xcode behaves so different from Script Debugger in this case?

The Xcode environment is running your newly build application against Xcode's debugger. A debugger like in SD is not debugging a process but debugging AppleScript's own VM. This is the big difference between these two.

SD is like debugging JavaScript code using Chrome's built-in development tools.
Xcode is like running Chrome in GDB trying to debug JavaScript code using GDB.

Last edited by DJ Bazzie Wazzie (2017-06-07 04:40:51 am)

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.037 seconds, 11 queries executed ]

RSS (new topics) RSS (active topics)