-1

I've done this before and it doesn't lend itself to googling the terms.

I'm trying to run an applescript without specifying osascript in the begining so that it's executable (i know you could do an alias), but I'm stubborn and need to figure out how I did this the first time.

$ head -2 original.scpt
#!/usr/bin/osascript
l�������i����.10����
$
$ head -2 new.scpt
l������������.10����
    i

As you can see, the original script has the shebang to osascript I tried prepending new.scpt with the same, but it did not work.

anyone know what this is called? does osacompile need a flag to generate this type of file that can be run by itself (assuming chmod +x) ?

thanks

dlite922
  • 1,924
  • 3
  • 24
  • 60

1 Answers1

2

The hashbang is correct but you need to save it as an uncompiled plain text file (.applescript) and chmod +x as needed.

foo
  • 254
  • 2
  • 3
  • Technically it doesn't even need the `.applescript` _extension_, the default when saved in Script Editor as text, or any _extension_ at all. As a plain text file with the `#!/usr/bin/osascript` [_shebang_](https://en.wikipedia.org/wiki/Shebang_(Unix)) (or other appropriate _shebang_) and made _executable_, e.g. `chmod +x filename`, it will execute as programmed. When executing an executable _script_ in Terminal, the _shebang_ and Terminal _environment_ governs how it's executed, not the _extension_ the _file_ might have, if any. – user3439894 Apr 04 '18 at 12:01
  • Indeed, it’s Script Editor that likes to stick `.applescript` on the file name. If you’re going to run it as a shell command, take it off to save the extra typing. Ancient DOS-isms 4 teh Lulz. – foo Apr 04 '18 at 18:36
  • how did I compile it the first time? I can't find the command to turn an applescript plain text into a compiled script that apparently still has the shebang. Adding the shebang manually to the compiled file didn't work (even with chmod +x) – dlite922 Apr 11 '18 at 20:11
  • Don’t compile your AppleScript. Shell scripts are plain text. When saving your script in Script Editor, change File Format from “script” (`.scpt`) to “text” (`.applescript`). – foo Apr 11 '18 at 21:32