Do you need to change the width of your Safari or Firefox window, but only on the desktop of the currently active Space? Try using this AppleScript. Placed in the excellent program Butler, you can even use a key combination to toggle the width.
Here's the script:
[robg adds: This script includes a reference to the Play Sound app; you'll either need that, or you'll want to remove the line that references it. I haven't tested this one.]
Here's the script:
(* Thanks to:
JNSoftware LLC, founded by Jonathan Nathan. See http://macscripter.net/viewtopic.php?id=23453
and
Tip "10.5: Find current Space number via AppleScript " of macosxhints See: http://www.macosxhints.com/article.php?story=20080227075244778 *)
set safariNr to get_space_binding_for_application("com.apple.safari") -- on wich space is safari?
set firefoxNr to get_space_binding_for_application("org.mozilla.firefox") -- on wich space is firefox?
set currentSpaceNr to get_my_space_number() -- on wich space are we?
tell application "Finder"
copy name of processes to MyProcesses -- wich browesr(s) is/are active?
end tell
-- change window-width of browser if active & on current space
if (("firefox-bin" is in MyProcesses) is true) and ((firefoxNr = currentSpaceNr) is true or (firefoxNr = 65544) is true) then
say "Firefox"
--tell application "Firefox" to activate
tell application "System Events" to tell process "firefox-bin"
activate
if size of window 1 = {596, 1111} then
set size of window 1 to {796, 1111}
else if size of window 1 = {796, 1111} then
set size of window 1 to {996, 1111}
else if size of window 1 = {996, 1111} then
set size of window 1 to {1296, 1111}
else if size of window 1 = {1296, 1111} then
set size of window 1 to {1543, 1111}
else if size of window 1 = {1543, 1111} then
set size of window 1 to {596, 1111}
else
set size of window 1 to {996, 1111}
end if
set position of window 1 to {4, 27}
end tell
end if
if (("safari" is in MyProcesses) is true) and ((safariNr = currentSpaceNr) is true or (safariNr = 65544) is true) then
say "Safari"
tell application "Safari"
activate
if bounds of window 1 = {4, 27, 600, 1138} then -- klein
set bounds of window 1 to {4, 27, 800, 1138} -- middel
else if bounds of window 1 = {4, 27, 800, 1138} then -- middel
set bounds of window 1 to {4, 27, 1000, 1138} -- normaal
else if bounds of window 1 = {4, 27, 1000, 1138} then --normaal
set the bounds of window 1 to {4, 27, 1300, 1138} -- groot
else if bounds of window 1 = {4, 27, 1300, 1138} then -- groot
set the bounds of window 1 to {4, 27, 1547, 1138} -- max
else if bounds of window 1 = {4, 27, 1547, 1138} then -- max
set bounds of window 1 to {4, 27, 600, 1138} -- klein
else
set bounds of window 1 to {4, 27, 1000, 1138} --normaal
end if
end tell
end if
tell application "Play Sound.app" to («event µSNDplay» alias "Hry HD:System:Library:Sounds:Sosumi.aiff") -- you need application "Play Sound"
-- handlers
on get_space_binding_for_application(application_bundle_id)
set application_bundle_id to my make_lowercase(application_bundle_id)
set app_bindings to my get_spaces_application_bindings()
try
get app_bindings as string
on error error_string
set app_bindings to my string_to_list(text 13 thru -20 of error_string, ", ")
end try
repeat with i from 1 to (count app_bindings)
if item i of app_bindings starts with ("|" & application_bundle_id & "|:") then return (item 2 of (my string_to_list(item i of app_bindings, ":"))) as number
end repeat
return 0
end get_space_binding_for_application
on get_spaces_application_bindings()
tell application "System Events" to tell spaces preferences of expose preferences to return (get application bindings)
end get_spaces_application_bindings
on get_my_space_number()
set xxVar to 0
tell application "System Events"
tell process "SystemUIServer"
set xVar to value of attribute "AXChildren" of menu bar 1
set cVar to count of xVar
repeat with iVar from 1 to cVar
set zVar to value of attribute "AXDescription" of item iVar of xVar
try
if zVar = "spaces-menu-extra" then
set xxVar to iVar
exit repeat
end if
end try
end repeat
end tell
end tell
if xxVar = 0 then
display dialog "Spaces Menu Extra not installed"
else
tell application "System Events"
tell process "SystemUIServer"
set theCurrentSpace to value of menu bar item xxVar of menu bar 1
end tell
end tell
return theCurrentSpace as number
end if
end get_my_space_number
on string_to_list(s, d)
tell (a reference to my text item delimiters)
set {o, contents} to {contents, d}
set {s, contents} to {s's text items, o}
end tell
return s
end string_to_list
on make_lowercase(the_string)
return do shell script "echo " & quoted form of the_string & " | /usr/bin/perl -pe 'use encoding utf8; s/(\\w)/\\L$1/gi'"
end make_lowercase
"SafariSpace " & safariNr & ", FirefoxSpace " & firefoxNr & ", currentSpace " & currentSpaceNr
•
[4,479 views]

