How to turn off Applescript guessing of Application name? - applescript

I am trying to target the application named "Adobe After Effects CC 2014" with applescript by using this code:
tell application "Adobe After Effects CC 2014"
activate
end tell
The thing is, I also have an application named "Adobe After Effects CC 2015" installed. If 2015 is not running there's no problem, the applescript behaves as it should (starts 2014 if it isn't running or brings it to the front if it is). But when 2015 is running, the script, when ran from the Script Editor automatically corrects "Adobe After Effects CC 2014" to "Adobe After Effects CC 2015" and runs it through 2015.
Is there a way to turn off this behaviour of automatically correcting the version number?
I know a solution could be to shut down 2015 before running the script, but in this situation I need it to keep running as well. I am on OS X 10.10.4.

This sounds like a creator-code problem (to use the old-school terminology). I believe that the applescript, once compiled, will use the bundle identifier of the application and the problem is that the bundle identifier is probably the same for both versions of the program.
You might want to try to right-mouse the 2014 version and open contents. Then open the Contents folder, and in there you will see Info.plist. Make a copy of this file and edit it to change the Bundle identifier field and add a 2014 to the end of the identifier (probably something like com.adobe...2014.

Apparently you can target the application using the full path according to the documentation. So it would be
tell application "/Applications/Adobe After Effects CC 2014/Adobe After Effects CC 2014.app"
activate
end tell

Try this:
tell application "Adobe After Effects CC 2014"
if application "Adobe After Effects CC 2015"
tell application "Adobe After Effects CC 2015"
close
tell application "Adobe After Effects CC 2014"
activate
end tell

Related

How To Open Files in Illustrator 2020 via AppleScript

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.

How to remove mapping/binding of application in AppleScript

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.

AppleScript assigning application to a variable

With multiple of InDesign installed, ScriptEditor tries to be smart about which version the script should run. However, I'm looking to DRY up my script so that I only have to change the application name once throughout my script.
There is a similar question ( Applescript path to application using variable ) but this doesn't work for everything. The question is, why doesn't this work for everything?
The following works as expected:
tell application "Adobe InDesign CS5.5"
log name --"Adobe InDesign CS5.5.app"
log full name --"Mactastic:Applications:Adobe InDesign CS5.5:Adobe InDesign CS5.5.app:"
end
A little DRYing action:
set v to "Adobe InDesign CS5.5"
set a to application v
log name of a --"Adobe InDesign CS5.5"
log full name of a
--SYNTAX ERROR: Expected end of line, etc. but found property
--"name" is highlighted in the ScriptEditor
Here is another example that works as expected:
set f to (choose file)
tell application "Adobe InDesign CS5.5"
open f without showing window
end tell
However, this fails to compile like before:
set f to (choose file)
set v to "Adobe InDesign CS5.5"
set a to application v
tell a
open f without showing window
end
--SYNTAX ERROR: Expected “given”, “with”, “without”, other parameter name, etc. but found class name.
--"window" is highlighted in the ScriptEditor
My Environment:
OSX 10.6.8
ScriptEditor 2.3 (118)
Applescript 2.1.2
EDIT: The end game in this is that I was hoping to abstract some of the InDesign functionality into my own classes, like so:
InDesign.scpt - a class that abstracts InDesign functionality
on new()
copy me to self
--do some initializing
return self
end new
on _version()
return "Adobe InDesign CS5.5"
end _version
on _application()
return application _version()
end _application
on _open(path)
tell _application() to open path without showing window
end _open
my_script.scpt - uses the abstracted InDesign.scpt above
set InDesign to (load script file ("my:path:to:scripts:" & "Indesign.scpt"))'s new()
InDesign's _open("my:path:to:indd:file.indd")
It's a good chance that the above isn't really possible in AppleScript and ObjectiveC is where I should be looking to do this type of thing. However, it seems that certain things do work like "tell _application() to open path" but "tell _application() to open path without showing window" does not.
How about:
set theApplication to "Adobe InDesign CS5.5"
using terms from application "Adobe InDesign CS5.5"
tell application theApplication
--do your thing here
end tell
end using terms from
The using terms from is used to let a script compile otherwise nothing in your tell application theApplication block will compile that is indesign specific. Using terms is quite common when an application (when the application is a webservice or remote machine) doesn't exists or isn't accessible at compile time.

How can I get the currently open file's path in photoshop (cs5) with applescript?

How can I get the currently open file's path in photoshop (cs5) with applescript?
I'm using CS5 on Mac OSX 10.7
I've tried the answer below and it gives the following error in the Applescript Editor:
error "Adobe Photoshop CS5 got an error: Can’t get document 1.
Invalid index." number -1719 from document 1
UPDATE: I have tested the code below in CS5 and Mac OS 10.7 and can confirm that this works even with a simple switch of tell application "Adobe Photoshop CS4" to tell application "Adobe Photoshop CS5". The error that you are getting is the result of there either not being a document open in the first place since you are targeting document 1. You can easily check for this with the following:
tell application "Adobe Photoshop CS5"
set documentCount to count documents
if documentCount > 0 then
set theDocument to document 1
set theFilePath to file path of theDocument
return theFilePath
else
-- no documents open. what to do?
end if
end tell
OLD ANSWER: I don't have CS5 (yet), but here it is for CS4, and I imagine CS5's version won't be too different, if at all, since Adobe has done a good job normalizing the API since CS3:
tell application "Adobe Photoshop CS4"
set theDocument to document 1
set theFilePath to file path of theDocument
return theFilePath
end tell
--> Result: Macintosh HD:path:to:file:filename.ext

Create AppleScript for a program that isn't installed on the current computer

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.

Resources