Tôi đang gặp sự cố với một tập lệnh shell sử dụng một phần nhỏ của Applescript. Khi tôi biên dịch nó với trình soạn thảo Applescript nó hoạt động. Nó không mặc dù trong một kịch bản shell.lỗi osascript/cú pháp: Dự kiến cuối dòng nhưng tìm thấy tên lệnh. (-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)
Đây là mã 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 (làm việc):
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
[cập nhật]/[giải quyết]
này đã chăm sóc bất kỳ loại vấn đề nào tôi đã cố gắng sửa đổi bản ghi chép để hoạt động trong địa ngục kịch bản:
## 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...
Nó rất mát mẻ mà bạn có thể đặt AppleScript tinh khiết trực tiếp vào một kịch bản shell. ;-)
Cảm ơn bạn đã giải thích. Tôi thực sự đã tìm ra một cách tuyệt vời để đưa bản ghi trực tiếp vào kịch bản lệnh shell mà không phải trải qua tất cả công việc sửa đổi nó để hoạt động. (xem ở trên) - –