我遇到了使用一小部分Applescript的shell腳本的問題。當我用Applescript編輯器進行編譯時,它可以工作。它不通過shell腳本。osascript /語法錯誤:預計結束行但找到命令名稱。 (-2741)
44:49: syntax error: Expected end of line but found command name. (-2741) 23:28: syntax error: Expected end of line but found 「after」. (-2741)
這裏是shell代碼:
osascript -e 'tell application "System Events" -e 'activate'
osascript -e 'tell process "Application 10.5" -e 'set frontmost to true' -e 'end tell'
osascript -e 'delay 1' -e 'keystroke return' -e 'delay 1' -e 'keystroke return'
end tell
AppleScript的(即作品):
tell application "System Events"
activate
tell process "Application 10.5"
set frontmost to true
end tell
delay 1
keystroke return
delay 1
keystroke return
end tell
[更新]/[解決]
這照顧了我嘗試修改applescript以在其中工作時出現任何類型的問題地獄腳本:
## shell script code
echo "shell script code"
echo "shell script code"
## applescript code
osascript <<EOF
tell application "Scriptable Text Editor"
make new window
activate
set contents of window 1 to "Hello World!" & return
end tell
EOF
## resume shell script...
這是非常酷的,你是能夠直接把純粹的AppleScript到一個shell腳本。 ;-)
感謝您的解釋。我實際上已經想出了一個很好的方法,可以將applescript直接放到shell腳本中,而無需經過修改它的所有工作。 (往上看) - –