我嘗試做什麼:如何獲得最前端的應用程序的名稱使用AppleScript,並用它來獲取文件路徑
當我在我的文字編輯器之一(文字編輯,笑談,FoldingText)是我想這個AppleScript來顯示文件路徑。
我想要最前面的窗口應用程序讓我的應用程序名稱很好,很容易,然後我可以在下一步要求POSIX路徑。
問題:
劇本已經99%,但我失去了一些東西。當我嘗試使用的activeApp
變量它不工作,我得到這個錯誤:
Error Number:System Events got an error: Can’t get application {"TextEdit"}.
-1728
這裏的腳本:
tell application "System Events"
set activeApp to name of application processes whose frontmost is true
--This doesn't work either:
--do shell script "php -r 'echo urldecode(\"" & activeApp & "\");'"
tell application activeApp
set myPath to POSIX path of (get file of front document)
end tell
display dialog myPath
end tell
如果我交流activeApp
與"TextEdit"
一切正常。幫助將不勝感激。
也許有什麼東西在這裏,可以幫助:Get process name from application name and vice versa, using Applescript
嘗試部分太棒了。非常靈活,並且使得所有不同的應用程序輸出正確的路徑(只要我測試了這個,就立即停止寫入IF條件)的手工工作。 Apropos,「如果」我可以得到這個與nvALT工作,那麼我甚至比我想象的還多。 – pattulus
你可以用'tell application'System Events'來告訴(處理1最前面是真的)如果name是「nvALT」那麼((系統屬性「HOME」)&「/ Notes /」)和文本字段的值窗口1的工具欄1的組1中的「1」和「.txt」)'。 – user495470
這很好。謝謝。但是當我運行這個腳本時,它將刪除路徑開頭的文本,所以'/ users/username/path/to/file'就成爲'sername/path/to/file'。任何想法爲什麼? – drstevok