Skip to content

Instantly share code, notes, and snippets.

@andrewvmail
Last active October 6, 2020 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewvmail/4837ad87431dbf923995e17da31b6aca to your computer and use it in GitHub Desktop.
Save andrewvmail/4837ad87431dbf923995e17da31b6aca to your computer and use it in GitHub Desktop.
KB maestro open terminal modified to open using iTerm2, taken from https://forum.keyboardmaestro.com/t/execute-a-script-in-terminal/4853/15 ```cd ~/Library/Application\ Support/Keyboard\ Maestro/Keyboard\ Maestro\ Actions ```
# Description: Part of a KM action. Passes a command or script to the Terminal.
# Author: Tom Floeren <ecdltf@mac.com>, http://dflect.net
# Version: 2.1.0
# Mod. Date: 2017-12-06
set winFront to system attribute "KMPARAM_Bring_Terminal_to_foreground"
set winNew to system attribute "KMPARAM_New_Terminal_window"
set theScript to do shell script "echo $KMPARAM_Script"
set kmVars to system attribute "KMPARAM_KM_variables"
# Get KM variables if any
if length of kmVars > 0 and kmVars does not start with "Optional." then
set inst to system attribute "KMINSTANCE"
set varDefs to ""
set c to 0
tell application id "com.stairways.keyboardmaestro.engine"
repeat with p in paragraphs of kmVars
if length of p > 0 then # Ignore empty lines
set v to getvariable p instance inst
set c to (c + 1)
set varDefs to varDefs & "km" & c & "=" & quoted form of v & ";" & space
end if
end repeat
end tell
set theScript to varDefs & theScript
end if
# Run script in Terminal
if winNew is "1" then
tell application id "com.googlecode.iterm2"
launch
set newWindow to (create window with default profile)
tell current session of current window
set cmd to "command"
write text theScript
end tell
if winFront is "1" then activate
end tell
else
tell application "Terminal"
launch
if winFront is "1" then activate
set windowCount to (count of the windows)
if windowCount is greater than 0 then
repeat with w from 1 to windowCount
if window 1 is busy or history of window 1 contains "[Process completed]" then
set frontmost of window 1 to false
else
do script theScript in window 1
set frontmost of window 1 to true
return
end if
end repeat
end if
tell window 1
do script theScript
set frontmost to true
end tell
end tell
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment