Skip to content

Instantly share code, notes, and snippets.

@forrestgrant
Created April 22, 2011 21:05
Show Gist options
  • Save forrestgrant/937673 to your computer and use it in GitHub Desktop.
Save forrestgrant/937673 to your computer and use it in GitHub Desktop.
Keep twitter app (mac) glued to an OS X space.
tell application "Twitter"
activate
end tell
delay 1
#First Time
set app_identifier to "com.twitter.twitter-mac"
set app_identifier to do shell script "echo " & quoted form of app_identifier & " | /usr/bin/perl -pe 'use encoding utf8; s/(\\w)/\\L$1/gi'"
set displayString to "Assign " & app_identifier & " to Space:"
set defaultAnswer to 0
set theNumber to 3
set app_construct to (run script "{|" & app_identifier & "|: " & theNumber & "}")
tell application "System Events"
tell spaces preferences of expose preferences
set app_layout to application bindings
end tell
end tell
set app_identifier to bundle identifier of (info for (path to frontmost application))
try
app_layout as number -- causes an error anyway
on error errstr
set app_locations to {}
set {TID, text item delimiters} to {text item delimiters, "{"}
set errstr to text item 2 of errstr
set text item delimiters to "}"
set errstr to text item 1 of errstr
set text item delimiters to ", "
set errstr to text items of errstr
set text item delimiters to TID
repeat with i in errstr
set o to offset of "|:" in i
tell i
set app_location to {}
set end of app_location to text 2 thru (o - 1)
set end of app_location to text (o + 2) thru -1
set end of app_locations to app_location
end tell
end repeat
end try
set spaces_bindings to {}
repeat with i from 1 to count app_locations
if app_identifier = item 1 of (item i of app_locations) then
--skip it
else
set spaces_bindings to spaces_bindings & (run script "{|" & item 1 of (item i of app_locations) & "|: " & item 2 of (item i of app_locations) & "}")
end if
end repeat
tell application "System Events"
tell expose preferences
tell spaces preferences
set application bindings to spaces_bindings
set spaces_bindings to app_construct & spaces_bindings
set application bindings to spaces_bindings
end tell
end tell
end tell
repeat with i from 1 to count app_locations
if app_identifier = item 1 of (item i of app_locations) then
--skip it
else
set spaces_bindings to spaces_bindings & (run script "{|" & item 1 of (item i of app_locations) & "|: " & item 2 of (item i of app_locations) & "}")
end if
end repeat
tell application "System Events"
tell expose preferences
tell spaces preferences
set application bindings to spaces_bindings
set spaces_bindings to app_construct & spaces_bindings
set application bindings to spaces_bindings
end tell
end tell
end tell
#Second Time
set app_identifier to "com.twitter.twitter-mac"
set app_identifier to do shell script "echo " & quoted form of app_identifier & " | /usr/bin/perl -pe 'use encoding utf8; s/(\\w)/\\L$1/gi'"
set displayString to "Assign " & app_identifier & " to Space:"
set defaultAnswer to 0
set theNumber to 2
set app_construct to (run script "{|" & app_identifier & "|: " & theNumber & "}")
tell application "System Events"
tell spaces preferences of expose preferences
set app_layout to application bindings
end tell
end tell
set app_identifier to bundle identifier of (info for (path to frontmost application))
try
app_layout as number -- causes an error anyway
on error errstr
set app_locations to {}
set {TID, text item delimiters} to {text item delimiters, "{"}
set errstr to text item 2 of errstr
set text item delimiters to "}"
set errstr to text item 1 of errstr
set text item delimiters to ", "
set errstr to text items of errstr
set text item delimiters to TID
repeat with i in errstr
set o to offset of "|:" in i
tell i
set app_location to {}
set end of app_location to text 2 thru (o - 1)
set end of app_location to text (o + 2) thru -1
set end of app_locations to app_location
end tell
end repeat
end try
set spaces_bindings to {}
repeat with i from 1 to count app_locations
if app_identifier = item 1 of (item i of app_locations) then
--skip it
else
set spaces_bindings to spaces_bindings & (run script "{|" & item 1 of (item i of app_locations) & "|: " & item 2 of (item i of app_locations) & "}")
end if
end repeat
tell application "System Events"
tell expose preferences
tell spaces preferences
set application bindings to spaces_bindings
set spaces_bindings to app_construct & spaces_bindings
set application bindings to spaces_bindings
end tell
end tell
end tell
repeat with i from 1 to count app_locations
if app_identifier = item 1 of (item i of app_locations) then
--skip it
else
set spaces_bindings to spaces_bindings & (run script "{|" & item 1 of (item i of app_locations) & "|: " & item 2 of (item i of app_locations) & "}")
end if
end repeat
tell application "System Events"
tell expose preferences
tell spaces preferences
set application bindings to spaces_bindings
set spaces_bindings to app_construct & spaces_bindings
set application bindings to spaces_bindings
end tell
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment