I want to create an executable file that when run will send a popup. I have the code for the popup
osascript -e 'tell app "Finder" to display dialog "message"'
but don't know how to create an executable file.
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.
Sign up to join this communityI want to create an executable file that when run will send a popup. I have the code for the popup
osascript -e 'tell app "Finder" to display dialog "message"'
but don't know how to create an executable file.
This gives you an .app which will run your AppleScript when opened.
Write your shell script in a text file, including the shebang.
If you're just using AppleScript, you can use osascript as the shebang:
#!/usr/bin/osascript
tell app "Finder" to display dialog "message"
Set the executable bit on the file.
chmod +x /path/to/file
This gives you a file which will run your shell script when opened.
#!/usr/bin/osascript
and then the content of the file can be a multi-line applescript (tell app "Finder" to display dialog "message"
) ... but your answer of saving as an application using Script Editor is a far better solution
– Josh
May 16 '19 at 13:24
osascript
in the question until after commenting and after that point it was too late to retract my downvote. If you make an edit to the answer then the site will let me change my vote!
– Josh
May 16 '19 at 14:15
#
is a comment character in AppleScript, it should be possible to combine grg's answer and this one to create a polyglot file that is both an app and a script.
– Jörg W Mittag
May 16 '19 at 19:14
.app
files are actually directories, I would not expect that to work.
– Wildcard
May 16 '19 at 19:58
You can save it as a script by putting this in a plaintext file and save it as something like dialog.sh:
#!/bin/bash
osascript -e 'tell app "Finder" to display dialog "message"'
Then making the file executable in the terminal by running chmod +x /path/to/dialog.sh
.
Execute in terminal by running /path/to/dialog.sh
osascript
... seems to me you should just make the shebang #!/usr/bin/osascript
and then the content of the file can be a multi-line applescript (tell app "Finder" to display dialog "message"
) ... but still seems like a workaround for the "proper" way of making an AppleScript executable from the finder: saving as an application
– Josh
May 16 '19 at 13:23
osascript
in the question until after commenting and after that point it was too late to retract my downvote. If you make an edit to the answer then the site will let me change my vote!
– Josh
May 16 '19 at 14:15
display dialog "message"
– Alexander O'Mara May 16 '19 at 19:50