我的腳本正在打開應用程序的舊版本(我寫的)。我搜索了HD並找不到舊的應用程序。新版本位於應用程序文件夾中。該腳本位於腳本文件夾中。Applescript打開錯誤版本的OS X應用程序
我做了一個新文件夾,並將腳本和新的應用程序放入其中。運行腳本仍然會打開錯誤的應用程序。 App2是問題的孩子。
錯誤路徑從哪裏來?
如何:
將腳本指向正確的應用程序?我不想要腳本中的路徑。
找到舊的應用程序並刪除它?
property checkInterval : 5 -- Number of seconds between checks. Adjust to requirement.
global App1WasOpen, GUIScriptingWasEnabled, previousText
on run
-- When the script starts up, note if App1 is running and GUI Scripting is enabled.
tell application "App1" to activate
tell application "System Events"
set App1WasOpen to (application process "App1" exists)
set GUIScriptingWasEnabled to (UI elements enabled)
end tell
-- Enable GUI Scripting if nec. and give the 'previousText' variable an initial value.
switchGUIScripting(true)
set previousText to ""
end run
on idle
-- Each time the script's polled by the system, check that App1's open.
tell application "System Events" to set App1IsOpen to (application process "App1" exists)
if (App1gIsOpen) then
set App1WasOpen to true
-- Get the latest value for 'beam'.
tell application "App1"
set hdg to getHeading
set beam to hdg as string
end tell
if ((count beam) < 3) then set beam to text -3 thru -1 of ("000" & beam)
-- If it's changed since the last check, enter it into App2 and keep it for later checks.
if (beam is not previousText) then
--display dialog "Opening App2" buttons {"OK"}
tell application "App2" to launch
--activate application "App2"
tell application "System Events"
set startTime to current date
repeat until exists (text field 1 of window "App2" of application process "App2")
if (current date) - startTime is greater than 5 then
error "Could not find text field 1 of window AppB of application process App2"
exit repeat
end if
delay 0.2
end repeat
tell application process "App2"
try
set value of text field 1 of window "App2" to beam
end try
end tell
end tell
--tell application "App1" to activate
set previousText to beam
end if
-- Request the next 'idle' event in 'checkInterval' seconds' time.
return checkInterval
else if (App1WasOpen) then
-- App1 was open at the last check, but isn't now. Tell this script applet to quit.
quit
-- It'll actually quit on the next idle event, so request a short interval.
return 1
end if
end idle
-- Unless GUI Scripting was already on when the script started to run, turn it on or off as per the parameter.
on switchGUIScripting(onOff) -- 'onOff' is 'true' for on, 'false' for off.
if (not GUIScriptingWasEnabled) then
tell application "System Events"
activate
set UI elements enabled to (onOff)
end tell
end if
end switchGUIScripting
-- When this applet's told to quit, restore the previous GUI Scripting state before it does.
on quit
switchGUIScripting(false)
continue quit
end quit
跟帖: 我用「在Finder中顯示」上的應用程序的圖標,在碼頭點我17個Xcode的檔案,我刪除了。現在,該腳本有一個「出現-10660類型的錯誤」的重複消息,並且App2從不打開。
我打開腳本編輯器,將代碼複製到一個新的腳本窗口,並用不同的名稱編譯它。仍然不打開App2。
你試過'mdfind -name App2'? – user495470 2013-03-16 09:34:36
有趣 - 在Xcode輸出中找到一對夫婦,在發送的電子郵件中找到一對,但不在應用程序或文檔中。我將編輯OP以告訴已完成的工作和結果。 – Mike 2013-03-16 11:38:51