Here are several options (none of them have been tested, so test and see which one works for you):
Option 1:
tell application "iTerm2" to activate
tell application "System Events" to tell process "iTerm2" to keystroke "h" using command down
Note: Keystroke may be replaced with m if you want iTerm2 to be minimized to the dock with the Genie effect.
Option 2:
tell application "Finder"
set visible of process "iTerm2" to false
end tell
Option 3:
tell application "System Events" to tell process "iTerm2" to set visible to false
Note: The process name may just be iTerm instead of iTerm2. I opened iTerm on my Mac and then Activity Monitor
, and the Process Name
that it shows is iTerm
. Please change accordingly if it does not work for you.
Links and Resources
Here is a great WikiBooks link that describes exactly what you need.
Please let me know which option works for you so I can edit the question and only include the option that works.
Edit:
If you make the iTerm window the frontmost application (Be careful you don't want to make the AppleScript window the frontmost application), try this script:
tell application "System Events"
set frontProcess to first process whose frontmost is true
set visible of frontProcess to false
end tell
Best Answer
If you want the iTerm2 window to stay open and active for further use, you cannot use
command
withcreate window with default profile
.You need to use the
write
command in proper context, e.g.:The above example AppleScript code used with
osascript
:"echo hello"
in the example AppleScript code with your command, e.g.:"uwm"
Note:
osascript
can execute the example AppleScript code from a file using, e.g.:From the iTerm2 AppleScript Dictionary:
Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.