![在應用程式開啟時阻止應用程式/觸發 applescript](https://rvso.com/image/1646035/%E5%9C%A8%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E9%96%8B%E5%95%9F%E6%99%82%E9%98%BB%E6%AD%A2%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%2F%E8%A7%B8%E7%99%BC%20applescript.png)
當打開特定應用程式時,有沒有辦法運行簡單的告訴應用程式退出。
例如,如果我打開 Spotify,是否可以觸發腳本來退出應用程式。
謝謝!
答案1
當打開特定應用程式時,有沒有辦法運行簡單的告訴應用程式退出。
簡短回答:是的
較長的答案:
我想到了以下幾種方法...
有付費的應用被稱為事件腳本那在眾多之中事件它可以做出反應,一類是應用程式活動其中包含 、Application activated
、Application deactivated
、Application will launch
和Application launched
。Application quit
事件腳本兩者都適用蘋果腳本 腳本和外殼腳本。
看一下事件腳本。在這篇文章發表時,它是美國應用商店 5.99 美元,但可以從開發者網站下載免費演示。
筆記:我不隸屬於 EventScripts 的開發人員,只是產品的滿意使用者。
例子 蘋果腳本 程式碼:
on run eventArgs
set thisTrigger to (trigger of eventArgs)
if thisTrigger is "Application launched" then
set appName to |applicationName| of eventArgs
if appName is "Spotify" then
tell application appName to quit
end if
end if
end run
一個免費的替代方案是錘勺,儘管人們可能會發現它並不像例如那樣容易實現和使用事件腳本。
這是一個例子的程式碼習慣手錶對於目標應用有推出然後使用關閉它蘋果腳本 程式碼:
例子 盧阿 程式碼:
function applicationWatcher(appName, eventType)
if (eventType == hs.application.watcher.launched) then
if (appName == "Spotify") then
hs.applescript('tell application "Spotify" to quit')
end
end
end
appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start()
這將被放置在〜/.hammerspoon/init.lua 文件與錘勺在背景運行,當目標應用是推出,它被告知退出蘋果腳本。
筆記:我不隸屬於 Hammerspoon 的開發者,只是產品的滿意使用者。