Skip to content

Commit

Permalink
Merge pull request #165 from thshdw/applescript-fixes
Browse files Browse the repository at this point in the history
Applescript fixes
  • Loading branch information
Matt Turner committed Feb 24, 2016
2 parents 924561b + 99b300b commit 7d317a7
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Shuttle/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ - (void) openHost:(NSMenuItem *) sender {
NSArray *passParameters = @[escapedObject, terminalTheme, terminalTitle];

// Check if Url
NSURL* url = [NSURL URLWithString:[sender representedObject]];
NSURL* url = [NSURL URLWithString:escapedObject];
if(url)
{
[[NSWorkspace sharedWorkspace] openURL:url];
Expand Down
4 changes: 2 additions & 2 deletions Shuttle/Shuttle-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.5</string>
<string>1.2.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.2.5</string>
<string>1.2.6</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Binary file modified Shuttle/apple-scpt/iTerm-stable-current-window.scpt
Binary file not shown.
Binary file modified Shuttle/apple-scpt/iTerm-stable-new-tab-default.scpt
Binary file not shown.
Binary file modified Shuttle/apple-scpt/iTerm-stable-new-window.scpt
Binary file not shown.
Binary file modified Shuttle/apple-scpt/iTerm2-nightly-current-window.scpt
Binary file not shown.
Binary file modified Shuttle/apple-scpt/iTerm2-nightly-new-tab-default.scpt
Binary file not shown.
Binary file modified Shuttle/apple-scpt/iTerm2-nightly-new-window.scpt
Binary file not shown.
Binary file modified Shuttle/apple-scpt/terminal-current-window.scpt
Binary file not shown.
Binary file modified Shuttle/apple-scpt/terminal-new-tab-default.scpt
Binary file not shown.
Binary file modified Shuttle/apple-scpt/terminal-new-window.scpt
Binary file not shown.
6 changes: 6 additions & 0 deletions apple-scripts/compile-Terminal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
echo "compiling applescripts for OS X terminal..."
osacompile -o ~/Git/shuttle/Shuttle/apple-scpt/terminal-new-window.scpt -x ~/Git/shuttle/apple-scripts/terminal/terminal-new-window.applescript
osacompile -o ~/Git/shuttle/Shuttle/apple-scpt/terminal-current-window.scpt -x ~/Git/shuttle/apple-scripts/terminal/terminal-current-window.applescript
osacompile -o ~/Git/shuttle/Shuttle/apple-scpt/terminal-new-tab-default.scpt -x ~/Git/shuttle/apple-scripts/terminal/terminal-new-tab-default.applescript

7 changes: 7 additions & 0 deletions apple-scripts/compile-iTermNightly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
echo "compiling applescripts for iTerm Nightly..."
osacompile -o ~/Git/shuttle/Shuttle/apple-scpt/iTerm2-nightly-new-window.scpt -x ~/Git/shuttle/apple-scripts/iTermNightly/iTerm2-nightly-new-window.applescript
osacompile -o ~/Git/shuttle/Shuttle/apple-scpt/iTerm2-nightly-current-window.scpt -x ~/Git/shuttle/apple-scripts/iTermNightly/iTerm2-nightly-current-window.applescript
osacompile -o ~/Git/shuttle/Shuttle/apple-scpt/iTerm2-nightly-new-tab-default.scpt -x ~/Git/shuttle/apple-scripts/iTermNightly/iTerm2-nightly-new-tab-default.applescript


7 changes: 7 additions & 0 deletions apple-scripts/compile-iTermStable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
echo "compiling applescripts for iTerm Stable..."
osacompile -o ~/Git/shuttle/Shuttle/apple-scpt/iTerm-stable-new-window.scpt -x ~/Git/shuttle/apple-scripts/iTermStable/iTerm-stable-new-window.applescript
osacompile -o ~/Git/shuttle/Shuttle/apple-scpt/iTerm-stable-current-window.scpt -x ~/Git/shuttle/apple-scripts/iTermStable/iTerm-stable-current-window.applescript
osacompile -o ~/Git/shuttle/Shuttle/apple-scpt/iTerm-stable-new-tab-default.scpt -x ~/Git/shuttle/apple-scripts/iTermStable/iTerm-stable-new-tab-default.applescript


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--for testing uncomment the "on run" block
--on run
-- set argsCmd to "ps aux | grep [s]sh"
-- CommandRun(argsCmd)
-- scriptRun(argsCmd)
--end run

on scriptRun(argsCmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- set argsCmd to "ps aux | grep xcode"
-- set argsTheme to "Homebrew"
-- set argsTitle to "Custom title"
-- CommandRun(argsCmd, argsTheme, argsTitle)
-- scriptRun(argsCmd, argsTheme, argsTitle)
--end run

on scriptRun(argsCmd, argsTheme, argsTitle)
Expand All @@ -23,7 +23,11 @@ on CommandRun(withCmd, withTheme, theTitle)
end tell

tell application "iTerm"
create window with profile withTheme
try
create window with profile withTheme
on error msg
create window with profile "Default"
end try
tell the current window
tell the current session
set name to theTitle
Expand All @@ -33,11 +37,16 @@ on CommandRun(withCmd, withTheme, theTitle)
end tell
end tell
else
--assume that iTerm is open and open a new tab
--assume that iTerm is open and open a new tab
try
tell application "iTerm"
activate
tell the current window
create tab with profile withTheme
try
create tab with profile withTheme
on error msg
create tab with profile "Default"
end try
tell the current tab
tell the current session
set name to theTitle
Expand All @@ -49,7 +58,11 @@ on CommandRun(withCmd, withTheme, theTitle)
on error msg
--if all iTerm windows are closed the app stays open. In this scenario iTerm has no "current window" and will give an error when trying to create the new tab.
tell application "iTerm"
create window with profile withTheme
try
create window with profile withTheme
on error msg
create window with profile "Default"
end try
tell the current window
tell the current session
set name to theTitle
Expand All @@ -60,4 +73,4 @@ on CommandRun(withCmd, withTheme, theTitle)
end try
end if
end tell
end CommandRun
end CommandRun
11 changes: 7 additions & 4 deletions apple-scripts/iTermNightly/iTerm2-nightly-new-window.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- set argsCmd to "ps aux | grep [s]sh"
-- set argsTheme to "Homebrew"
-- set argsTitle to "Custom title"
-- CommandRun(argsCmd, argsTheme, argsTitle)
-- scriptRun(argsCmd, argsTheme, argsTitle)
--end run

on scriptRun(argsCmd, argsTheme, argsTitle)
Expand All @@ -22,13 +22,16 @@ on CommandRun(withCmd, withTheme, theTitle)
end if
end tell
tell application "iTerm"
create window with profile withTheme
try
create window with profile withTheme
on error msg
create window with profile "Default"
end try
tell the current window
tell the current session
set name to theTitle
set profile to withTheme
write text withCmd
end tell
end tell
end tell
end CommandRun
end CommandRun
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--for testing uncomment the "on run" block
--on run
-- set argsCmd to "ps aux | grep [s]sh"
-- CommandRun(argsCmd)
-- scriptRun(argsCmd)
--end run

on scriptRun(argsCmd)
Expand Down
64 changes: 44 additions & 20 deletions apple-scripts/iTermStable/iTerm-stable-new-tab-default.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- set argsCmd to "ps aux | grep [s]sh"
-- set argsTheme to "Homebrew"
-- set argsTitle to "Custom title"
-- CommandRun(argsCmd, argsTheme, argsTitle)
-- scriptRun(argsCmd, argsTheme, argsTitle)
--end run

on scriptRun(argsCmd, argsTheme, argsTitle)
Expand All @@ -13,29 +13,19 @@ on scriptRun(argsCmd, argsTheme, argsTitle)
CommandRun(withCmd, withTheme, theTitle)
end scriptRun

--to open in new tab have 3 conditions
--iTerm app is not open.
--iTerm app is open with no windows.
--iTerm app is open with at least one window.
on CommandRun(withCmd, withTheme, theTitle)
tell application "iTerm"
if it is running then
set curTerm to (current terminal)
try
set tmp to curTerm
on error
set curTerm to (make new terminal)
end try
tell curTerm
set newSession to (launch session withTheme)
tell the last session
reopen
activate
write text "clear"
write text withCmd
set name to theTitle
end tell
end tell
else
if it is not running then
--activate opens iTerm using default settings
activate
delay 0.2
close first window
--we don't want the defaults.
--lets close the first window and make our own
set newTerm to (make new terminal)
tell newTerm
set newSession to (launch session withTheme)
Expand All @@ -45,6 +35,40 @@ on CommandRun(withCmd, withTheme, theTitle)
activate
end tell
end tell
else
--iTerm is running get the window count
set windowCount to (count every window)
set curTerm to (current terminal)
if windowCount = 0 then
--app is running with no windows
--reopen opens iTerm using default settings
reopen
--we dont want the defaults.
--lets close this and make our own
terminate the first session of the first terminal
set newTerm to (make new terminal)
tell newTerm
set newSession to (launch session withTheme)
tell newSession
write text withCmd
set name to theTitle
activate
end tell
end tell
else
--app is running with open windows
--so do things in the current terminal
tell curTerm
set newSession to (launch session withTheme)
tell the last session
reopen
activate
write text "clear"
write text withCmd
set name to theTitle
end tell
end tell
end if
end if
end tell
end CommandRun
end CommandRun
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- set argsCmd to "ps aux | grep [s]sh"
-- set argsTheme to "Homebrew"
-- set argsTitle to "Custom title"
-- preLoad(argsCmd, argsTheme, argsTitle)
-- scriptRun(argsCmd, argsTheme, argsTitle)
--end run

on scriptRun(argsCmd, argsTheme, argsTitle)
Expand All @@ -16,9 +16,12 @@ end scriptRun
on preLoad(withCmd, withTheme, theTitle)
tell application "iTerm"
if it is not running then
--activate opens iTerm using default settings
activate
delay 0.2
close first window
--we don't want the defaults.
--lets close the first window and make our own
end if
end tell
CommandRun(withCmd, withTheme, theTitle)
Expand Down
2 changes: 1 addition & 1 deletion apple-scripts/terminal/terminal-current-window.applescript
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--for testing uncomment the "on run" block
--on run
-- set argsCmd to "ps aux | grep [s]sh"
-- CommandRun(argsCmd)
-- scriptRun(argsCmd)
--end run

on scriptRun(argsCmd)
Expand Down
55 changes: 33 additions & 22 deletions apple-scripts/terminal/terminal-new-tab-default.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,49 @@
-- set argsCmd to "ps aux | grep [s]sh"
-- set argsTheme to "Homebrew"
-- set argsTitle to "Custom title"
-- preLoad(argsCmd, argsTheme, argsTitle)
-- scriptRun(argsCmd, argsTheme, argsTitle)
--end run

on scriptRun(argsCmd, argsTheme, argsTitle)
set withCmd to (argsCmd)
set withTheme to (argsTheme)
set theTitle to (argsTitle)
preLoad(withCmd, withTheme, theTitle)
CommandRun(withCmd, withTheme, theTitle)
end scriptRun

on preLoad(withCmd, withTheme, theTitle)
on CommandRun(withCmd, withTheme, theTitle)
tell application "Terminal"
if it is running then
reopen
if it is not running then
--if this is the first time Terminal is running you have specify window 1
--if you dont do this you will get two windows and the title wont be set
set newTerm to do script withCmd in window 1
activate
tell application "System Events"
tell process "Terminal"
delay 0.2
keystroke "t" using {command down}
set newTerm's current settings to settings set withTheme
set custom title of front window to theTitle
else
--Terminal is running get the window count
set windowCount to (count every window)
if windowCount = 0 then
--Terminal is running but no windows are open
--run our script in a new window
activate
reopen
do script withCmd in window 1
else
--Terminal is running and we have a window run in a new tab
reopen
activate
tell application "System Events"
tell process "Terminal"
delay 0.2
keystroke "t" using {command down}
end tell
end tell
end tell
do script withCmd in front window
end if
set current settings of selected tab of front window to settings set withTheme
set title displays custom title of front window to true
set custom title of selected tab of front window to theTitle
end if
my CommandRun(withCmd, withTheme, theTitle)
activate
end tell
end preLoad

on CommandRun(withCmd, withTheme, theTitle)
tell application "Terminal"
do script withCmd in front window
set current settings of selected tab of front window to settings set withTheme
set title displays custom title of front window to true
set custom title of selected tab of front window to theTitle
end tell
end CommandRun
end CommandRun

0 comments on commit 7d317a7

Please sign in to comment.