Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fix docker quickstart terminal for iTerm2 version 2.9 and later
on write_to_file(this_data, target_file, append_data)
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
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 \"\"
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
create window with default profile
tell current session of current window
write contents of file \"/tmp/alfredscript\"
end tell
end if
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
Copy link

devinus commented Mar 6, 2016

This doesn't seem to work with iTerm2 2.9.20160206.

Copy link

devinus commented Mar 6, 2016

Copy link

maxromanovsky commented Mar 6, 2016

Agreed, initial version works fine

Copy link

syhily commented Mar 15, 2016

Tks, initial version works.

Copy link

adriaant commented Apr 7, 2016

Initial version is the one to use, indeed.

Copy link

gejiawen commented Apr 15, 2016

Yeah, the first version works fine indeed.

Copy link

skyuplam commented May 1, 2016

Agree that only the version works. Thanks @devinus

  • iTerm2 version: 2.9.20160426 beta

Copy link

dgraziotin commented May 30, 2016

Many thanks for this.

Copy link

mkows commented Jun 2, 2016

Copy link

pedrocarrico commented Jun 8, 2016

Yup, works fine for iTerm2 ver 3.0.0 👍

Copy link

Jake-Day-Williams commented Jun 14, 2016

Works for iTerm2 Build 3.0.0

For those of you new to terminal commands copy and paste this into your terminal.
open -a Atom /Applications/Docker/"Docker Quickstart"/Contents/Resources/Scripts/iterm.scpt

This will open the file you need to copy over in the Atom Editor. You might see strange characters in the file. That's okay. Copy over them with the code above and save the file.

If you're using another Editor replace "Atom" with the name of it. Example:
open -a TextWrangler /Applications/Docker/"Docker Quickstart"/Contents/Resources/Scripts/iterm.scpt

If you're new or rusty with the Terminal here's some insights. (I'm on a Mac.)

cd Applications will call the current user applications. Typing "ls" will typically list just some Chrome stuff in there.
cd /Applications will call the path your machine applications are on. Those are the ones you see listed in Finder.

When you need to cd a Folder or File name that uses spaces and not dashes or underscores you need to wrap the full name in quotations. We did this with "Docker Quickstart" for example.

Copy link

zanuka commented Jun 15, 2016

thanks, the script patch works perfectly in Build 3.0.2

Copy link

jenga commented Jun 27, 2016

Thanks for this! I can confirm that revision works with Build 3.0.2 . However, your latest revision does not.

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:

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

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

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