The argument for osascript -e
can contain newlines:
osascript -e 'set x to "a"
say x'
You can also specify multiple -e
arguments:
osascript -e 'set x to "a"' -e 'say x'
Or if you use a heredoc, bash
interprets three characters (\
, $
, and `
) between <<END
and END
but no characters between <<'END'
and END
.
osascript <<'END'
set x to "a"
say x
END
Edit:
Since osascript can operate with a heredoc (ie take input from /dev/stdin) then one can just write the script as a whole file and prepend with the correct shebang line:
#!/usr/bin/env osascript
set x to "a"
say x
This also allows you to save your apple script as a actual program in ~/Applications/.app using the following procedure (changing for your script's name):
mkdir -p ~/Applications/<APP_NAME>.app/Contents/MacOS
touch ~/Applications/<APP_NAME>.app/Contents/MacOS/<APP_NAME>
open -A TextEdit ~/Applications/<APP_NAME>.app/Contents/MacOS/<APP_NAME>
Ensure that both the script file in .../MacOS/ and the matches
Unfortunately the icons now appear to be hardcoded, it used to be the case that you could just name a folder Movies in your home folder and it would gain the icon but not anymore.
According to this: https://stackoverflow.com/questions/8380562/adding-buttons-to-finder-toolbar
DropBox are going to pretty extreme lengths to get their icon in the sidebar, using code injection.
In other words, I don't think it is possible I'm afraid.
Best Answer
In general, no. Each application is sandboxed, code signed and updated by the Mac App Store update process. Some apps are restricted by system integrity protection.
In specific yes, you could disable sip if needed. You could disable gatekeeper and modify the app and re-enable gatekeeper. The engineering work to maintain a general script would be days to get a framework done and then hours to days Pre update.