Skip to content

Instantly share code, notes, and snippets.

@tzarskyz
Forked from loshlee/Slate Manager
Created July 29, 2013 02:37
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 tzarskyz/6101864 to your computer and use it in GitHub Desktop.
Save tzarskyz/6101864 to your computer and use it in GitHub Desktop.
set default_settings to "# This is the default .slate file.
# If no ~/.slate file exists this is the file that will be used.
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
# Resize Bindings
bind right:alt resize +10% +0
bind left:alt resize -10% +0
bind up:alt resize +0 -10%
bind down:alt resize +0 +10%
bind right:ctrl;alt resize -10% +0 bottom-right
bind left:ctrl;alt resize +10% +0 bottom-right
bind up:ctrl;alt resize +0 +10% bottom-right
bind down:ctrl;alt resize +0 -10% bottom-right
# Push Bindings
bind right:ctrl;cmd push right bar-resize:screenSizeX/3
bind left:ctrl;cmd push left bar-resize:screenSizeX/3
bind up:ctrl;cmd push up bar-resize:screenSizeY/2
bind down:ctrl;cmd push down bar-resize:screenSizeY/2
# Nudge Bindings
bind right:shift;alt nudge +10% +0
bind left:shift;alt nudge -10% +0
bind up:shift;alt nudge +0 -10%
bind down:shift;alt nudge +0 +10%
# Throw Bindings
bind 1:ctrl;alt throw 0 resize
bind 2:ctrl;alt throw 1 resize
bind 3:ctrl;alt throw 2 resize
bind right:ctrl;alt;cmd throw right resize
bind left:ctrl;alt;cmd throw left resize
bind up:ctrl;alt;cmd throw up resize
bind down:ctrl;alt;cmd throw down resize
# Focus Bindings
bind right:cmd focus right
bind left:cmd focus left
bind up:cmd focus up
bind down:cmd focus down
bind up:cmd;alt focus behind
bind down:cmd;alt focus behind
# Window Hints
bind esc:cmd hint"
set myHome to ((path to home folder) as string)
set _path to myHome & "Slate sets:"
set targ1 to POSIX path of _path
set targ2 to POSIX path of myHome
set user_dotSlate to (targ2 & ".slate")
set user_dotSlate_js to (targ2 & ".slate.js")
set user_slates to {user_dotSlate, user_dotSlate_js}
set the item_count to the number of items in user_slates
repeat with i from 1 to the item_count
set this_item to item i of user_slates
try
if (POSIX file (this_item)) as alias exists then
if i is 1 then -- first list item
set has_dotSlate to true
else if i is the item_count then -- last list item
set has_dotSlate_js to true
end if
end if
on error
if i is 1 then -- first list item
set has_dotSlate to false
else if i is the item_count then -- last list item
set has_dotSlate_js to false
end if
end try
end repeat
(*
if has_dotSlate and has_dotSlate_js then
display dialog "\".slate\" and \".slate.js\" are present."
else if has_dotSlate and not has_dotSlate_js then
display dialog "\".slate\" is present but \".slate.js\" is not present."
else if not has_dotSlate and has_dotSlate_js then
display dialog "\".slate\" is not present but \".slate.js\" is present."
else if not has_dotSlate and not has_dotSlate_js then
display dialog "Neither \".slate\" nor \".slate.js\" is present."
end if
*)
try
do shell script "mkdir" & space & quoted form of (POSIX path of _path)
end try
try
set name_target to alias (POSIX file (targ1 & "default.slate")) --file name is already taken at destination if no error occurs.
on error
do shell script "echo" & space & (quoted form of default_settings) & space & ">" & space & quoted form of (POSIX path of _path) & "default.slate"
end try
if has_dotSlate then
try
set name_target to alias (POSIX file (targ1 & "original.slate")) --file name is already taken at destination if no error occurs.
on error
my backupdotslate(user_dotSlate, (targ1 & "original.slate"))
end try
end if
if has_dotSlate_js then
try
set name_target to alias (POSIX file (targ1 & "original.slate.js")) --file name is already taken at destination if no error occurs.
on error
my backupdotslate(user_dotSlate_js, (targ1 & "original.slate.js"))
end try
end if
set ls to (list folder _path)
set ld to {}
repeat with i in ls
if i is not in {".DS_Store"} then
set ld to ld & i
end if
end repeat
display dialog "Open configuration file for editing or continue activating Slate with the set you'll now select?" buttons {"Open Config", "Continue"} default button 2
if button returned of the result is "Open Config" then
try
choose from list ld with prompt "Choose Slate configuration to open in TextWrangler:"
do shell script "open -a TextWrangler.app" & space & (quoted form of targ1) & (quoted form of (result as text))
my bounce_Slate()
end try
else
choose from list ld with prompt "Choose Slate configuration to activate:"
if result is false then
my bounce_Slate()
else
if (result as text) ends with ".js" then
do shell script "rm" & space & user_dotSlate & ";" & "ditto" & space & (quoted form of targ1) & (quoted form of (result as text)) & space & user_dotSlate_js
else
do shell script "rm" & space & user_dotSlate & ";" & "ditto" & space & (quoted form of targ1) & (quoted form of (result as text)) & space & user_dotSlate
try
do shell script "rm" & space & user_dotSlate_js
end try
end if
my bounce_Slate()
end if
end if
on backupdotslate(original_Slate, backup_Target)
set thesource to (quoted form of (POSIX path of original_Slate))
do shell script "ditto" & space & thesource & space & quoted form of backup_Target
end backupdotslate
on bounce_Slate()
tell application "System Events"
set appname to "Slate"
if appname is in name of every process then
set the_process to the process appname
set pid to the unix id of the_process
else
set pid to ""
end if
end tell
if pid is not "" then do shell script ("kill -9 " & pid)
tell application "Finder" to open application file id "com.slate.Slate"
end bounce_Slate
@loshlee
Copy link

loshlee commented Oct 1, 2022

Still works. Please allow me to suggest changing "TextWrangler" to "BBEdit".

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