Pretty simmilar, but not equal to: How to check in AppleScript if an app is running, without launching it - via osascript utility
I want an automator app, which starts iterm and calls the input file in vim. If iterm is allready open (not really required to check if its vim; would be nice though!) I want to split the window and open the file in the split.
My attempt:
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
Invoked with just run, both displays give the right answer to weather or not the app is running allready! If I use the app however (drop a file on it) it seems, that it first starts iTerm because of some tell statement and then always says its allready open!
run script and putting everything into " " doesn't work. Any suggestions to why this may happen or how I can get the expected behaviour?