1

I've been using this solution to decompile AppleScript files before adding them to a Git repository. It basically creates a filter using osacompile and osadecompile to convert between plain text source and a compiled AppleScript.

I noticed however, that some applications referenced in the scripts are unexpectedly starting on git add and the culprit is osadecompile.

Example:

When I run osadecompile script.scpt against the following script, a Firefox starts up:

tell application "Firefox"
    open location "https://apple.stackexchange.com"
end tell

It doesn't open the location specified, however the Firefox process gets started and remains running.

Questions:

  • Is there anything I can do to avoid this?

  • What exactly is happening here? Does the script run in background (other actions from the scripts - like say "something" do not seem to run)?

2 Answers 2

3

I am not sure what the technical reason for this is, but accessing the AppleScript dictionary of some applications seems to require opening them. When I try opening the AppleScript dictionary of Firefox through Script Editor, Firefox will also be opened. When I try opening the dictionary of Keynote v5.3 (iWork'09 version), the app is opened, while when I try this with Keynote v7.0.5, the app is not opened. As Script Editor exhibits the same behavior, I am not sure there's any way to avoid this with osadecompile.

I did not read the Apple Developer documentation on AppleScript in detail, but I noticed this sentence which also suggests some applications need to be opened to access their AppleScript dictionary while some don’t:

An aete is useful in 10.4 and earlier, in both Carbon and Cocoa applications, to provide a dictionary that scripting languages can use without launching the application.

1
  • You are right, the Script Editor also starts Firefox when opening the example script.
    – techraf
    Jan 9, 2017 at 8:50
0

Here is an AppleScript solution that will let you compile or decompile the code in either Terminal or Script Editor without Firefox actually launching. In fact, this same concept worked for every application I tried.

This works for me on macOS Big Sur.

tell application "Finder"
    set |Firefox| to name of (application file id "org.mozilla.firefox" as alias)
end tell

tell application |Firefox|
    open location "https://apple.stackexchange.com"
end tell
1
  • RE: "In fact, this same concept worked for every application I tried." -- While this method will work with the particular use case, it will not work in cases when the target application is using AppleScript code that is specific to the target application. As an example, using Numbers, code addressing e.g. active sheet, table, etc. will not compile if wrapped in a tell block formed by using this method. Jan 17, 2021 at 6:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .