But that didn't work and do anything. None of the scripts there worked in fact. Also I think it won't do what I want either because it might open a new iTerm window and that I don't want.
I want to run it in my profile that I always keep open. I use this to open and close my iTerm
And that is where I want the new tab with the path opened. How can I do this?
I am trying to figure out now, how to wrap it all in an if statement that will check if iTerm is currently active. If it is, it will do this whole action, if not, it will do the whole action + trigger a keystroke to open iTerm for me. I can do the keystroke part (with sending a key code).
How do I do the if cause though to see if the app is currently active. I found something like this but couldn’t make it work.
The script (the new version) activates iTerm if it’s in the background, and it launches it if it isn’t running. Just download the macro again, I have updated it with the new script.
I have and it does activate it, but it doesn’t pull up and show my iTerm window. For it to do it, it will need to press the hotkey.
I tried putting the hotkey there :
tell application "Keyboard Maestro Engine" to set thePath to getvariable "itermPath"
if application "iTerm" is running then
tell application "iTerm"
activate
if exists window 1 then
tell current window
create tab with default profile
tell current session to write text "cd" & space & quoted form of thePath
end tell
else
create window with default profile
tell current window
tell current session to write text "cd" & space & quoted form of thePath
tell application "System Events" to key code 13 using {option down, control down, shift down, command down}
end tell
end if
end tell
end if
But that doesn’t work. Nor was putting the tell application in the first if clause worked for some reason but putting this key code alone as applescript in new macro worked and run the key code properly.
Yeah as I said, I have tried your updated script and it does activate iTerm but it does not activate iTerm itself. I am running iTerm in full screen by pressing cmd + return so it is “full screen”. Just checked now and your script works well when it is not in full script but when it is, it is not working.
It should I think be easily solved with an if clause that will check if iTerm is active. If it is, do the action that you have sent, and if not, do the same action + hotkey. I just am not really sure about that if clause.
Yeah, but you need if clause because if I add that line of code in the end, yes it will work well when iTerm is not active. But if I am already in iTerm and activate the macro, it will instead hide iTerm from full screen. That’s why you need the if clause.
tell application "iTerm"
if not frontmost then tell application "System Events" to key code 13 using {option down, control down, shift down, command down}
end tell
tell application "Keyboard Maestro Engine" to set thePath to getvariable "itermPath"
tell application "iTerm"
activate
if exists window 1 then
tell current window
create tab with default profile
tell current session to write text "cd" & space & quoted form of thePath
end tell
else
create window with default profile
tell current window
tell current session to write text "cd" & space & quoted form of thePath
end tell
end if
if not frontmost then tell application "System Events" to key code 13 using {option down, control down, shift down, command down}
end tell