[英]how to close an active document in Mac OS using shell script
我正在使用蘋果腳本關閉活動文檔,如下所示
tell application "Microsoft Word"
activate
try
if not (exists active document) then error number -128
close active document saving yes
on error
end try
end tell
想要使用shell腳本執行類似的操作。 我想優雅地關閉它,不想使用kill命令。 而且我不想用osascript來調用蘋果腳本。 我想要使用本機Shell命令的優美方式
嗨,您可以在shell代碼中使用osascript
#!/bin/sh
osascript <<EOF
tell application "$1"
close (every window whose name is "$2")
end tell
EOF
編譯此代碼並制作filename.sh
或者你可以使用
#!/bin/sh
osascript <<EOF
tell application "Preview"
close (every window whose name is "$1")
end tell
EOF
要從cmd使用此命令,請鍵入$。/ file_name預覽應用程序名稱
在這里我使用了https://ss64.com/osx/osascript.html的引用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.