【发布时间】:2014-06-12 14:52:08
【问题描述】:
非常相似,但不等于: How to check in AppleScript if an app is running, without launching it - via osascript utility
我想要一个自动化应用程序,它启动 iterm 并在 vim 中调用输入文件。 如果 iterm 已经打开(实际上不需要检查它是否是 vim;不过会很好!)我想拆分窗口并在拆分中打开文件。
我的尝试:
on run {input}
-- get the file path incl extention
set inputFilePath to POSIX path of input
display dialog appIsRunning("iTerm")
tell application "iTerm"
if it is running then
display dialog "yes"
tell current terminal
tell the last session
write text ",w" -- split window vertically
write text openInVim
end tell
end tell
else
display dialog "no"
set openInVim to "vim " & quoted form of inputFilePath
set text item delimiters to "/"
set parentDir to text items 1 thru -2 of inputFilePath
tell i term application "iTerm"
activate
tell current terminal
tell the last session
delay 0.1
write text "cd " & parentDir & "; clear"
write text openInVim
end tell
end tell
end tell
end if
end tell
end run
on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning
通过 just run 调用,两个显示都会给出天气的正确答案,或者应用程序是否已经运行! 但是,如果我使用该应用程序(在其上放置文件),它似乎首先启动 iTerm,因为某些告诉语句,然后总是说它已经打开!
运行脚本并将所有内容放入“”中不起作用。 关于为什么会发生这种情况或如何获得预期行为的任何建议?
【问题讨论】:
标签: applescript automator