1

I'm trying to execute an AppleScript .app thats compressed.

unzip -p file.app.zip | open -

or

open < $(unzip -p file.app.zip)

Is this possible?

  • did you try it ? what happens – Ruskes Sep 29 '18 at 1:30
  • It just prints the open help options – lily Sep 29 '18 at 1:31
  • Open what ? Where ? unzip will create new folder (with same name as zip folder) – Ruskes Sep 29 '18 at 1:46
  • 1
    There is a reason that apps are distributed on.dmg. You can mount the disk that is compressed an run th app. Other Unix tolls don't treat the app as one thing but a load of separate files and directories – Mark Sep 29 '18 at 10:05
  • 1
    @Buscar웃, You said, "... unzip will create new folder (with same name as zip folder)", that is not true with the -p option used in the OP, e.g. unzip -p ...! From the unzip man page: "-p extract files to pipe (stdout)." – user3439894 Sep 29 '18 at 12:58
1

As you are dealing with a zip compressed application .app, which is an application bundle with many files in it, I believe you'll have to extract the app to disk first to open it, because the open command to open an application is in the form of open -a ... and does not take input from stdout.

The following assumes that the app name in file.app.zip is file or the exact name of the app within the .zip file:

unzip -oq "file.app.zip" -d /tmp; open -a "/tmp/file.app"; sleep 1; rm -r "/tmp/file.app"

The above compound command line extracts the file.app.zip to /tmp and then opens it, waits a second and then deletes the /tmp/file.app. Note that the value of the sleep command may need to be adjusted in order to not have the app deleted before it's opened and finished running.

Note that the contents of /tmp, which is actually /private/tmp, is automatically deleted upon reboot. So the compound command line could be shortened if you don't care if the app remains in /tmp' until next reboot:

unzip -oq "file.app.zip" -d /tmp; open -a "/tmp/file.app"
  • 2
    Would replacing the ; with && add an extra layer of error handling? My understanding is the && ensures the next command only runs if the previous finished with no error. – Graham Miln Sep 29 '18 at 13:58
0

You are asking the open command to open content from stdin. open can be made to read from stdin but it will open the contents in at text editor--which isn't what you want.

Try using osascript directly: If the zipped file is simply AppleScript, then you accomplish this with the following.

unzip -p file.zip | osascript - 

From the osascript manpage:

osascript will look for the script in one of the following three places:

  1. Specified line by line using -e switches on the command line.

  2. Contained in the file specified by the first filename on the command line. This file may be plain text or a compiled script.

  3. Passed in using standard input. This works only if there are no filename arguments; to pass arguments to a STDIN-read script, you must explicitly specify '-' for the script name.

  • 2
    Did you actually test to see what you posted works? I'm asking because it errors out in my testing. – user3439894 Sep 29 '18 at 12:52
  • Of course. The command does assume that the unzipped file is plain text AppleScript commands. – ephsmith Sep 29 '18 at 14:21
  • @user3439894, see my previous comment. This solution works for plain ole AppleScript. Your answer is more appropriate given an AppleScript application. – ephsmith Sep 29 '18 at 14:35
  • @ephsmith, thank you for the answer, but this also errors for me with: 0:1: syntax error: A unknown token can't go here. (-2740). My test .zip contains an AppleScript with the following: do shell script "touch /Users/$USER/Desktop/test" – lily Oct 8 '18 at 7:05

You must log in to answer this question.

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