我的脚本正在打开旧版本的应用程序(我写的)。我搜索了高清,找不到旧的应用程序。新版本位于applications文件夹中。该脚本位于脚本文件夹中。
我创建了一个新文件夹并将脚本和新应用程序放入其中。运行该脚本仍会打开错误的应用程序。 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
跟进: 我在Dock中的应用程序图标上使用了“Show in Finder”,指向我删除的17个Xcode档案。现在该脚本有一个重复的消息“发生了-10660型错误”,App2永远不会打开。
我打开了脚本编辑器,将代码复制到新的脚本窗口并使用不同的名称进行编译。仍然没有打开App2。
答案 0 :(得分:0)
尝试使用以下命令查找应用程序ID:
set appID to get id of application "/Applications/Safari.app"
找到后,请参阅id而不是
tell application id "com.apple.Safari" to launch