OSX 10.13.6, AI 2020, Applescript Editor Version 2.10 (194), AppleScript 2.7
(Don't think this should matter, but am not prepared to upgrade the OS, as NVidia still hasn't released drivers for the TitanXP GPU the system uses).
Sticking to AppleScript in this discussion. No "Just Use JavaScript" suggestions please, unless you can confirm or deny that the problem also occurs in JavaScript.
Am wondering if Adobe has made a change to their Illustrator API, as, since upgrading to the new 2020 version, Applescript files that used to work with earlier versions of Illustrator are now having difficulty opening files when referred to by an alias, or a variable in posix-style format.
InDesign does not seem to have been affected, as every time a major version upgrade occurs I run a script on some several hundred .INDD files to prevent the "save-as" dialog next time they are used, which can mess up scripting. That script still works. Haven't tried Photoshop yet, but most of the automation I use there is in the form of their internal "Actions".
After a little research, am thinking they may have tinkered with HFS support, resulting in unanticipated consequences.
Illustrator 2020 can open a file referenced by a hard-coded string in posix-style format, but it cannot open that same file from a variable, either an HFS-style alias, or quoted posix-style string, i.e,
set theHFSPath to "Mac HD:Users:Mac User:Documents:Illustrator:myFile.ai"
set thePosixPath to quoted form of theHFSPath
# i.e., '/Volumes/Mac HD/Users/Mac User/Documents/Illustrator/myFile.ai'
Tell Application "Adobe Ilustrator"
# Opens OK
open POSIX file "/Volumes/Mac HD/Users/Mac User/Documents/Illustrator/myFile.ai" without dialogs
# Crashes with "Adobe Illustrator got an error: The specified file could not be opened because it could not be found"
open theHFSPath as alias without dialogs
# open (theHFSPath as alias) also crashes
# Crashes with "Adobe Illustrator got an error: File/Folder expected"
open POSIX file thePosixPath without dialogs
# open POSIX file (quoted form of thePosixPath)
# without quoting HFSPath above also crashes
End Tell
Am suspecting Adobe maybe dropped a low-level routine that dealt with HFS, and with this routine failing, the open command cannot "see" the file to open it.
Not much on the 'tubes yet, but I have run across:
http://forum.latenightsw.com/t/apple-script-for-illustrator-2020-javascript-code-was-missing/2167
from a little less than a week ago, which seems to be describing the same issue.
Anyone else run across this, or know how to get around it?
'k, the issue does not seem to be with regards to HFS or POSIX paths, per se. I very much appreciate all the replies and comments, and still believe there is a bug in AI 2020's open command; will be heading over to Adobe to see if anyone else has reported it.
It was very confusing that if one hard-coded the path, i.e.,
Tell Adobe Illustrator
open POSIX file "/Users/Mac User/Documents/Illustrator/myFile.ai" without dialogs
End Tell
it would work.
However, turns out that with AI 2020, the culprit is the optional "without dialogs" parameter in conjunction with an alias or POSIX-style variable reference to the file.
According to the dictionary one would append
without dialogs
to the open command in order to bypass any regular dialogs AI might present when opening the file.
Though this worked fine in AI 2019, it is causing the open command to crash in AI 2020, even though the AI 2020 dictionary still shows "dialogs" as an optional boolean parameter with the same syntax as the 2019 version.
To test this hypothesis, I cranked up an older Mini that still has AI 2019 on it, and tried:
set theFile to "Users:Mac User:Documents:Illustrator:myFile.ai"
open theFile as alias without dialogs
As expected, this worked just fine, as it has for years.
In AI 2020, with the same file reference,
open theFile as alias without dialogs
crashes the open command.
Remove without dialogs and it opens as expected.
So, the only work-around for now seems to be ignoring the dialogs parameter.
Hopefully Adobe will either update their AS dictionary or fix the bug.
Take care!
The following examples work exactly as expected on AI 2020 (which I’ve just installed) and CC 2017 running under macOS 10.14.6:
set alis to alias "Macintosh HD:Users:foo:test.ai" -- an existing file
tell application "Adobe Illustrator" to open alis
-- AI opens test.ai document
set furl to POSIX file "/Users/foo/test.ai"
tell application "Adobe Illustrator" to open furl
-- AI opens test.ai document
This works as expected too (notwithstanding the awful quality of AI’s error messages):
set furl to POSIX file "/Users/foo/xxxxx.ai" -- a non-existent file
tell application "Adobe Illustrator" to open furl
-- SE reports error "Adobe Illustrator got an error: AppleEvent handler failed." number -10000
..
However, the following does not work as you’d expect:
set pth to "/Users/foo/test.ai"
tell application "Adobe Illustrator" to open POSIX file pth
The open command neither opens the file nor sends back an error message explaining why not. This is one of those maddenly quirky and unintuitive gotchas with AppleScript’s object specifiers, made doubly confusing by AI’s lousy error handling.
Short explanation: The script is effectively telling AI to open POSIX file "…" of <Illustrator>, and since the app’s dictionary doesn’t include a POSIX file class, the app is unable to resolve that reference. Whereas what you need is to first say POSIX file "…" of <AppleScript>, which tells AS to build a POSIX file value (which it knows how to do) and then pass the constructed value to the open command.
This is why it’s always a good idea to build alias, POSIX file, date, etc values outside of any tell app… blocks. It’s a crude rule of thumb, but easy to remember. (Best not to think about AS behaviour too hard as you’ll only make your head hurt.)
--
Now, if you’re seeing different behaviors under macOS 10.15 then that implies something else has changed (presumably in the OS) which is causing knock-on effects elsewhere; if that’s the case, update your original post with more details.
[updated to add]
These work correctly on AI 2020 and earlier (macOS 10.14.6):
set f to POSIX file "/Users/foo/test.ai" -- existing file
tell application "Adobe Illustrator" to open f
-- AI opens document
set f to POSIX file "/Users/foo/test.ai" -- existing file
tell application "Adobe Illustrator" to open f with dialogs
-- AI opens document
set f to POSIX file "/Users/foo/test.ai" -- existing file
tell application "Adobe Illustrator" to open f without dialogs
-- AI opens document
set f to POSIX file "/Users/foo/xxxxxx.ai" -- non-existent file
tell application "Adobe Illustrator" to open f without dialogs
-- AI throws File Not Found error
This also works correctly on AI 2020:
set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open f
However, while these work correctly on AI 2019, on AI 2020 they incorrectly throw a File Not Found error even though the file exists:
set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open f with dialogs
-- error "Adobe Illustrator got an error: The specified file could not be opened because it could not be found" number 9032
set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open f without dialogs
-- error "Adobe Illustrator got an error: The specified file could not be opened because it could not be found" number 9032
set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open f with options {class:open options, add to recent files:true}
-- error "Adobe Illustrator got an error: The specified file could not be opened because it could not be found" number 9032
Therefore, can confirm there is a [non-crashing] BUG in AI 2020’s open command that causes it to fail when its direct parameter is an alias value and one or more positional parameters are also given.
For now, you’ll need to work around this bug by coercing your alias value to a POSIX file value[1] prior to passing it to AI 2020’s open command:
set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open (f as «class furl») with options {class:open options, add to recent files:true}
Alternatively, it may be a good time rework your AppleScript code to eliminate using alias values and use POSIX file values throughout. The ancient (pre-OSX) alias value type has long been deprecated throughout the rest of macOS in favor of modern security-scoped bookmarks, which may be why it’s suddenly breaking in a freshly-updated app like AI 2020.
Alas, AppleScript was relegated to maintenance mode some years ago so I doubt Apple will ever sort out its absolute mess of old/new/working/broken file types; they’re just something you’ll need to be aware of and work around in your own code. (i.e. Don’t bother filing an AppleScript feature request with Apple; unless it’s a security hole they’ll likely just ignore it.)
You can if you want file an Adobe bug report on AI 2020’s open command. No guarantees they’ll fix it; they may just tell you the same thing—stop passing it [deprecated] alias values and use [supported] POSIX file values instead—but at least it’ll be on the record as WontFix and users can be made aware of it.
--
[1] Note that when coercing a value to POSIX file you must write f as «class furl», not f as POSIX file. This is due to a longstanding defect in AS which Apple are never going to fix.
Related
I have some AppleScript which I run via osascript on the command line.
The script itself looks like:
on run argv
set appname to item 1 of argv
set tmp to item 2 of argv
set jsfl_path to POSIX file tmp
if application appname is running then
tell application appname
with timeout of 600 seconds
open jsfl_path
end timeout
end tell
end if
end run
I updated Adobe CC Animate to the latest version. I was previously running the 2018 version. It turns out they renamed the file pattern. It used to be Adobe Animate CC 2018. Now it is Adobe Animate 2019.
Here is where the problem starts. In my script I was sloppy and change the name to Adobe Animate CC 2019.
When I ran the AppleScript, it produced a dialog to Choose Application. In my haste, I accidentally mapped it to the wrong program.
I'd like to remove this mapping. What I cannot find is where this mapping is stored. Does anyone know where this type of mapping gets saved?
It isn’t really stored anywhere, the Script Editor uses your declarations to determine where to load the scripting terminology from. Recompiling the script after making an edit should reset things, otherwise you can restart the Script Editor. Note that you need to use a specific bundle identifier or application name - using a variable to specify the application can be problematic, as the terminology is loaded at compile time.
I'd like to write an AppleScript program to do the following (Automator would be fine too):
I want to open the current active TextMate file (possibly there are several tabs open and other windows) with the application Transmit 2. (This will upload the file over FTP using Transmit's DockSend feature.)
Here I've used a specific application (TextMate) but ideally I'd like it to work for any file currently active in any application.
Ultimately I will assign a keyboard shortcut to run it.
Here's what I have so far:
tell application (path to frontmost application as text)
set p to path of document 1
end tell
tell application "Finder"
open POSIX file p using "Transmit 2"
end tell
I've tried many variants of this and nothing works.
EDIT:
I have found this page: http://wiki.macromates.com/Main/Howtos and someone has made exactly the script I'm looking for:
tell application "Transmit" to open POSIX file "$TM_FILEPATH"
This is for Transmit [not 2] and I think for TextMate pre v2. I get the error (when using Transmit 2):
Transmit 2 got an error: AppleEvent handler failed.
One of the updates to v2 has broken it (not sure which one).
There appear to be two steps to your problem. One, get the path to the document (or some other reference that allows you to later open the document), and, two, open the document in the desired application.
If the AppleScript is saved as an application, the frontmost application is the AppleScript you’re running, and so that path will be the path to the AppleScript application. In that case, I’m not aware of how to get the second-frontmost application.
However, if the application supports the scripts folder (go into AppleScript Editor‘s preferences, and enable “Show Script menu in menu bar”), you can save the script as a “Script“ in the User Scripts folder, and when run from the scripts menu the frontmost application will be the application you’re currently in.
You may want to display the p variable when testing to ensure that you are getting the correct path and not the path to the AppleScript.
As far as opening the document in another application (such as Transmit), the best way to do this is to talk to the application directly if it supports it:
tell application (path to frontmost application as text)
set p to path of document 1
end tell
--for testing: verify that the path is for the correct document
display dialog p
tell application "Transmit 2"
open p
end tell
I don’t have Transmit, but I’ve verified that this works if I replace “Transmit 2” with Textastic or Smultron 6.
If you do need to use the Finder to open the document, the Finder seems to prefer its paths as strings, and also seems to prefer a full path to the application. Something like this should work:
tell application (path to frontmost application as text)
set p to path of document 1
end tell
--for testing: verify that the path is for the correct document
--display dialog p
set transmitPath to path to application "Transmit 2"
set p to POSIX file p as string
tell application "Finder"
open file p using transmitPath
end tell
Again, I’ve tested this using Textastic and Smultron as the applications.
The most common solution for the problem you are trying to solve is to run an app that makes your Web server appear to be a mounted Mac disk. Transmit 4 has that feature, which Panic calls “Transmit Disk.” But there are a few other apps also — Transmit was not the first.
Your Mac apps (and AppleScripts) just see a typical Mac disk that they can save files to and read files from (the most basic of basic AppleScript tasks) and yet Transmit Disk (or similar app) is transparently mirroring any changes to that Mac disk to your Web server in the background. This makes all the network and FTP stuff totally go away and leaves you writing very simple scripts that do very powerful things to your Web server. You Save HTML documents on there, you Export image and movie files onto there as easily as you would Save them on your Desktop, and yet they are immediately published to your Web server. Even the only barely scriptable apps can Save their files onto a particular disk.
For example, if I have an HTML document open in BBEdit and I want to save a copy of that document to my Web server, it only takes a few lines of code, which would likely be similar in any AppleScript-able text editor (this script would also work verbatim in the free TextWrangler):
tell application "BBEdit"
set theHTMLSource to the contents of text window 1
make new document with properties {text:theHTMLSource}
save document 1 to file "Transmit Disk:index.html"
close document 1 saving no
end tell
Notice that the AppleScript above not only doesn’t have to know anything about SFTP or have any login credentials, it doesn’t even have to figure out the file path of my current document because it just takes the content right out of the current window. There are no POSIX pathnames, no shell scripts, no monkey business at all. And because this task and code is so simple, you could conceivably rewrite this script 20 times for 20 different apps that you may use, so that they can all Save a copy of their current document onto your Transmit Disk, and thus publish that document to your Web server.
And if I have a folder of images that goes along with that HTML document, I can ask Finder to duplicate that folder onto my Transmit Disk to publish it. With just one line of code:
tell application "Finder"
duplicate folder "images" of (the path to the desktop folder as alias) to the disk "Transmit Disk" replacing no
end tell
… but those images could also be exported out of Photoshop or any app, right onto the Transmit Disk, via AppleScript.
In short, the thing that all of your Mac apps have in common is they can all Save files to a Mac disk. They can’t necessarily all give you the pathnames to the documents they have open, or open those files with Transmit. And Mac apps and AppleScript were designed primarily to work with files Saved or Opened to/from local disks. So you gain a lot if you use something like Transmit Disk to make your Web server basically part of the AppleScript party, by making it appear to be just a plain old Mac disk.
I am new to shell scripting and I am trying to open some pdf files with terminal on mac, so I can script it later, however I cannot get them to open in Acrobat or even Photoshop when I specify the application. I have tried both open -a Acrobat ~/filename/.pdf and open -a "Adobe Acrobat 7.0 Professional" /(absolute url)/.pdf, and variations thereof.
It works great when I try it with preview or textedit and opens fine when I just use open, except some open in preview. Is there something screwy with Adobe that s preventing me from targeting the application or am I missing something simple? Any help would be much appreciated.
EDIT
After banging my head against a wall I found out that I was defining the absolute path wrong. I am not sure why it Acrobat and Photoshop do not need an absolute path when opening normally and does when specifying the application with -a but escaping the spaces in the path worked.
Example: /Applications/Adobe\ Acrobat\ 7.0\ Professional/Adobe\ Acrobat\ 7.0\ Professional.app/
The open command is specific to Mac OSX. I've updated your tags to reflect that.
If the application you're opening is in /Applications directory, you do not need the path. Just the application name. You do not need the .app suffix. The case in the name isn't important, but the exact spelling is, and if you application contains any spaces, you need to enclose the application's name in quotation marks.
I don't have Acrobat or Photoshop on my system, but if they contain revision numbers in the name, or they have spaces, you need to include them. For example:
$ open -a "Adobe Acrobat 7.0 Professional/Adobe Acrobat 7.0 Professional" foo.pdf
(I have no idea of the actual name. I don't have Acrobat on my system, and I have no plans on downloading that piece of whine-ware (defined as software that demand you update it more often than you actually use it).
I am trying to incorporate my applescript into xcode. the script works normally with applescript but not ran in xcode. I am trying to open the file for reading. here is the code
set Location to "US"
set DriverFile to "/Volumes/MacPrintDrivers/" & Location & "DriverInstall.txt"
set DriverInstallFile to POSIX file DriverFile
open for access DriverInstallFile
i have confirmed the file exists and i can display the contents. i can't seem to read this way in Xcode. the error i get is
«script» doesn’t understand the «event rdwropen» message. (error -1708)
ASOC (AppleScript Objective-C) has some problems with scripting addition commands (such as open for access). Sometimes you can work around this by saying tell current application to, e.g. tell current application to open for access. But for further details I suggest you get Shane Stanley's book: http://www.macosxautomation.com/applescript/apps/ He has explored this in great depth.
I'm trying to make two copies of an AppleScript, one that works for Entourage and one for out Outlook. I only have Entourage installed on the current computer.
According to the info on Microsoft's site, both applications have the same library of AppleScript commands, and I should be able to simply change the application name referenced within the script.
Changing:
Tell application "Microsoft Entourage"
to
Tell application "Microsoft Outlook"
Prevents me from saving the script because I don't have outlook installed on this computer. Is there any way around this? Do I need to use a text editor to edit the actual script file and change it there?
Thanks!
The following work-around may do the trick. On the computer where Entourage is installed, a using terms directive will let you compile the script, even if Outlook is not installed:
set theApp to a reference to application "Microsoft Outlook"
using terms from application "Microsoft Entourage"
tell theApp
get version
...
end tell
end using terms from
Upon compiling and saving the script the AppleScript Editor will bug you about the missing Outlook application, but it will nevertheless produce a compiled AppleScript file (.scpt).
Applescript is a pre-complied file format, meaning that every time you click "Save" it runs through a series of steps to ensure the script will work, but just short of actually running through the script's logic. Part of those steps is to look for the application to see if it exists on the Mac.
In short, if you want to save the script as an Applescript, you need the target application installed, otherwise you can save the script as a text file and move the file over to the target Mac to save as an Applescript over there.
It should be possible to make one script that works with both Entourage and Outlook, without bugging you if one isn't found either when you compile or when you run. I don't have either Entourage or Outlook but it should work like this:
using terms from application "Microsoft Entourage"
script theScript
tell application "Finder" to try
set theApp to application file id "Entourage's Bundle ID" as text
on error
set theApp to application file id "Outlook's Bundle ID" as text
end try
tell application theApp
-- do stuff
end tell
end script
end using terms from
store script theScript in "MyScript.scpt"
"using terms from" is only relevant when compiling the script - it isn't needed when running, though for some reason you'll still get bugged if that app isn't found. So by wrapping it around a script object and then writing out that script to file, the resultant script will still run but won't contain "using terms from" and so won't bug the user.
For getting a reference to the right app, Finder can look for it by ID and simply error if it isn't found rather than bugging the user. You'll need to insert the proper ID's there, I don't know what they are.