-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompile
executable file
·54 lines (48 loc) · 1.13 KB
/
compile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh -
# Compile the AppleScript or JavaScript for Automation source files
# provided as arguments, placing each compiled script in the same
# directory as its source.
if [ "$#" -lt 1 ]
then
printf %s\\n 'usage: compile script1 [script2 ...]' >&2
exit 1
fi
rc=0
for infile
do
case $infile in
*?.applescript)
osalang=AppleScript
outfile=${infile%.*}.scpt
;;
*?.js)
osalang=JavaScript
outfile=${infile%.*}.scpt
;;
*)
# Be conservative with oddly named files: use
# the default language and don't strip
# extensions.
osalang=AppleScript
outfile=$infile.scpt
;;
esac
shift
if osacompile -l "$osalang" -x -o "$outfile" -- "$infile"
then
# Collect the output filenames for the grand finale.
set -- "$@" "$outfile"
else
rc=$?
fi
done
# Hide the outputs' filename extensions, as Apple's Script Editor does.
# Discard the result printed by osascript(1), which I don't care about.
osascript - "$@" >/dev/null <<'EOF' && exit "$rc"
on run _argv
repeat with _arg in _argv
set _f to POSIX file _arg as alias
tell application "Finder" to set (extension hidden) of _f to true
end repeat
end run
EOF