Skip to content

Instantly share code, notes, and snippets.

@rtomaszewski
Created December 15, 2015 21:01
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 rtomaszewski/edff00a2a18b247bbcf7 to your computer and use it in GitHub Desktop.
Save rtomaszewski/edff00a2a18b247bbcf7 to your computer and use it in GitHub Desktop.
set itermExists to false
try
tell application "Finder" to get application file id "com.googlecode.iterm2"
set itermExists to true
end try
set terminalScpt to path to resource "terminal.scpt" in directory "Scripts"
set itermScpt to path to resource "iterm.scpt" in directory "Scripts"
if itermExists then
set a to path to application support from user domain
set p to POSIX path of a & "DockerToolbox/"
set default_terminal_file to p & "default_terminal"
do shell script "mkdir -p '" & p & "'"
set default_terminal to do shell script "default_terminal_file='" & default_terminal_file & "'; if [[ -f $default_terminal_file ]] && [[ -s $default_terminal_file ]]; then cat \"${default_terminal_file}\"; fi"
set terminalList to {"iTerm", "Terminal"}
if terminalList does not contain default_terminal then
set default_terminal to ""
end if
if default_terminal is not "" then
set answer to default_terminal
else
choose from list {"iTerm", "iTerm (Always)", "Terminal", "Terminal (Always)"} with title (name of current application as text) with prompt "Open using:" default items {"iTerm"}
set answer to result as text
# TODO: Instead of list, figure out how to do: 2 buttons + checkbox in below code
# set question to display dialog "Use Terminal or iTerm?" with title (name of current application as text) with icon note buttons {"Terminal", "iTerm", "Cancel"} default button 1
# set answer to button returned of question
end if
if answer is equal to "iTerm" then
run script itermScpt
else if answer is equal to "iTerm (Always)" then
do shell script "echo iTerm > '" & default_terminal_file & "'"
run script itermScpt
else if answer is equal to "Terminal" then
run script terminalScpt
else if answer is equal to "Terminal (Always)" then
do shell script "echo Terminal > '" & default_terminal_file & "'"
run script terminalScpt
end if
else
run script terminalScpt
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment