Thursday, November 23, 2017

#1 2016-07-19 08:58:52 am

krwllms
Member
Registered: 2016-01-28
Posts: 14

Script errors when ran in Xcode

The following script works perfectly in Script Editor but as soon as it's run in Xcode it errors. I can't work out what's going on.

Applescript:

try
   set a to path to desktop folder from user domain as text
   set b to "Spreadsheets/Daily Report.xlsx alias"
   set c to POSIX path of a & b
   set founditems to {c}
   set filepath to POSIX file (item 1 of founditems)
   tell application "Finder" to open filepath
on error
   display alert "Alias could not be found."
end try

Edit: I'm getting "AppleEvent timed out. (error -1712)" in Xcode.

Last edited by krwllms (2016-07-19 09:08:35 am)

Offline

 

#2 2016-07-19 09:58:09 am

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

Re: Script errors when ran in Xcode

Hi,

basically your script is too complicated, this does the same

Applescript:

try
   set a to path to desktop as text
   set b to "Spreadsheets:Daily Report.xlsx alias"
   tell application "Finder" to open file (a & b)
on error
   display alert "Alias could not be found."
end try

However in Xcode I recommend to use AppleScriptObjC code

Applescript:

set desktopFolder to POSIX path of (path to desktop)
set reportAlias to current application's NSURL's fileURLWithPath:(current application's NSString's stringWithFormat_("%@Spreadsheets/Daily Report.xlsx alias", desktopFolder))
set aliasExists to (reportAlias's checkResourceIsReachableAndReturnError:(missing value)) as boolean
if aliasExists then
   current application's NSWorkspace's sharedWorkspace()'s openURL:reportAlias
else
   display alert "Alias could not be found."
end if


regards

Stefan

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)