Last active
December 27, 2015 00:19
-
-
Save popavo/7236550 to your computer and use it in GitHub Desktop.
Show/hide TotalTerminal from AppleScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
All this script does is: | |
looks for the Visor window in Terminal.app | |
sets the TotalTerminalVisorExposeFrontmostAndVisibleProperties preference value to false | |
toggle both the `visible` and `frontmost` properties of Visor | |
rinse and repeat with TotalTerminalVisorExposeFrontmostAndVisibleProperties set to true | |
reset pref to original value | |
*) | |
-- look for the Visor window in Terminal.app | |
on getVisor() | |
local visorWindow | |
set visorWindow to missing value | |
tell application "Terminal" | |
set visorSettings to settings set "Visor" | |
-- Here I use the current settings of selected tab to find the Visor window. | |
-- It's not very sophisticated but it gets the job done | |
-- A better way would be to use the Visor profile exclusively for Visor window and | |
-- set a custom name in the "Window" tab of Visor's profile settings. Then test the | |
-- name of the window against that custom name | |
if (count of (every window whose current settings of selected tab is visorSettings)) > 0 then | |
set visorWindow to first window whose current settings of selected tab is visorSettings | |
--return first window whose current settings of selected tab is visorSettings | |
end if | |
end tell | |
return visorWindow | |
end getVisor | |
-- toggle frontmost of a window | |
on toggleFrontmost(visor) | |
try | |
delay 0.5 | |
tell application "Terminal" | |
set visorIsFrontmost to (get frontmost of visor) | |
set frontmost of visor to not visorIsFrontmost | |
get frontmost of visor | |
end tell | |
end try | |
end toggleFrontmost | |
-- toggle visible of a window | |
on toggleVisible(visor) | |
try | |
delay 0.5 | |
tell application "Terminal" | |
set visorIsVisible to (get visible of visor) | |
set visible of visor to not visorIsVisible | |
get visible of visor | |
end tell | |
end try | |
end toggleVisible | |
-- set defaults value and activate an app | |
on setExposeVisorWindowVisibilityPref(input, prevApp) | |
do shell script "defaults write com.apple.Terminal TotalTerminalVisorExposeFrontmostAndVisibleProperties -bool " & input | |
if not prevApp is equal to missing value then | |
tell application prevApp to activate | |
tell application "System Events" to tell application process prevApp to set frontmost to true | |
end if | |
end setExposeVisorWindowVisibilityPref | |
-- variable declarations | |
set frontmost_app to missing value | |
set current_front_and_visible_pref to missing value | |
set visor to missing value | |
-- get currently frontmost app | |
tell application "System Events" | |
set frontmost_app to name of first process whose frontmost is true | |
end tell | |
-- get currently set defaults value | |
if (do shell script "defaults read com.apple.Terminal TotalTerminalVisorExposeFrontmostAndVisibleProperties") = "1" then | |
set current_front_and_visible_pref to "YES" | |
else | |
set current_front_and_visible_pref to "NO" | |
end if | |
set visor to getVisor() | |
if visor is equal to missing value then | |
return 1 | |
end if | |
display dialog "Allow Visor access to frontmost/visible properties: Disabled" | |
setExposeVisorWindowVisibilityPref("NO", frontmost_app) | |
toggleFrontmost(visor) | |
toggleFrontmost(visor) | |
toggleVisible(visor) | |
toggleVisible(visor) | |
display dialog "Allow Visor access to frontmost/visible properties: Enabled" | |
setExposeVisorWindowVisibilityPref("YES", frontmost_app) | |
toggleFrontmost(visor) | |
toggleFrontmost(visor) | |
toggleVisible(visor) | |
toggleVisible(visor) | |
setExposeVisorWindowVisibilityPref(current_front_and_visible_pref, frontmost_app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment