Skip to content

Instantly share code, notes, and snippets.

@gnachman
Last active April 27, 2018 05:44
Show Gist options
  • Star 37 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save gnachman/f61614d0335e185787b0 to your computer and use it in GitHub Desktop.
Save gnachman/f61614d0335e185787b0 to your computer and use it in GitHub Desktop.
Fix docker quickstart terminal for iTerm2 version 2.9 and later
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
on alfred_script(q)
-- Write the command to run to a file. This is done because Applescript quoting is impossible to get right, esp. for backslashes.
write_to_file(q & return, POSIX file "/tmp/alfredscript", false)
-- Create this file, which prevents iTerm2 from restoring a saved window arrangement.
do shell script "touch ~/Library/Application' Support/iTerm/quiet'"
-- Test cases:
-- 1. iTerm2 running, has windows open. Should open a new window for Alfred command.
-- 2. iTerm2 running, no windows open. Should open a new window for Alfred command.
-- 3. iTerm2 not running, set to restores arrangement. Should not restore arrangement but open a new window for the Afred command.
-- 4. iTerm2 not running. No windows to restore. Should open a single window for the Alfred command.
-- 5. iTerm2 not running. Has windows to restore. Restores windows and then opens a new window for the Alfred command.
-- Compose a script. This is necessary because compiling in a 'tell application' command causes the app to be launched, which would happen prior to the creation of the quiet file.
set theScript to "
tell application \"iTerm.app\"
if (exists current window) then
tell current window to create tab with default profile
tell current session of current window
write contents of file \"/tmp/alfredscript\"
end tell
else
create window with default profile
tell current session of current window
write contents of file \"/tmp/alfredscript\"
end tell
end if
activate
end tell"
-- Invoke the script.
run script theScript
-- Clean up
do shell script "rm -f ~/Library/Application' Support/iTerm/quiet' /tmp/alfredscript"
end alfred_script
@zanuka
Copy link

zanuka commented Jun 15, 2016

thanks, the script patch works perfectly in Build 3.0.2

@jenga
Copy link

jenga commented Jun 27, 2016

Thanks for this! I can confirm that revision https://gist.github.com/gnachman/f61614d0335e185787b0/ea7a3f7b248390efa886557f6917e12a6c9c0cd6 works with Build 3.0.2 . However, your latest revision does not.

@sijnc
Copy link

sijnc commented Jun 28, 2016

Looks like Docker Toolbox has been patched but not yet released, I used the script from the commit and it worked great:

https://github.com/virajkanwade/toolbox/blob/b45ae79a4b7eb16e397b759c53cac8d5c0da134c/osx/mpkg/quickstart.app/Contents/Resources/Scripts/iterm.scpt

I used the cmd below to edit the file with sublime:

open -a "Sublime Text" /Applications/Docker/"Docker Quickstart Terminal.app"/Contents/Resources/Scripts/iterm.scpt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment