Showing posts with label scripts. Show all posts
Showing posts with label scripts. Show all posts

Saturday, May 16, 2009

Unscripted Friday: Internet Sharing Toggle (Applescript)

File: toggleinternetsharing.scpt
Language: Applescript
Download: http://gist.github.com/112789
Background: At work, I often share the Ethernet connection of my Macbook Pro over Airport, so that my iPhone can connect over Wi-Fi. However, at the end of the day, I switch Internet Sharing back off to free up the Airport, so that I can go online with my notebook wirelessly again on the go. I wanted a way to perform this task with just one click, and Applescript was my answer.

-- Internet Sharing Toggler: Toggle Internet Sharing on/off in OS X
-- 2009 May 16. Written for OS X 10.5.x.
-- Gordon Mei
-- Feel free to use and distribute however you'd like.

tell application "System Preferences"
activate
tell application "System Events"
tell process "System Preferences"
delay 0.5 --for running script again shortly after
click menu item "Sharing" of menu "View" of menu bar 1
delay 0.5
tell window "Sharing"
tell group 1
tell scroll area 1
tell table 1
tell row 10 --"Internet Sharing"
click checkbox 1
end tell
end tell
end tell
end tell
delay 0.5
if (exists sheet 1) then
tell sheet 1
click button "Start"
end tell
end if
end tell
end tell
delay 0.1
keystroke "w" using command down
end tell
end tell

Friday, May 15, 2009

Unscripted Friday: Hot Corner Toggle Off (Applescript)

File: togglehotcornersoff.scpt
Language: Applescript
Download: http://gist.github.com/111949

-- Hot Screen Off Toggler: Toggle all four hot corners off. This is the counterpart to the script that toggles all four hot corners on, for cases when a visitor comes over who isn't used to active screen corners.
-- 2009 May 14. Written for OS X 10.5.x.
-- Gordon Mei, with guidance from Pierre L. from Apple discussions
-- Feel free to use and distribute however you'd like.

tell application "System Preferences" to activate
tell application "System Events"
tell process "System Preferences"
tell menu bar 1
tell menu bar item "View"
delay 0.5
tell menu 1
click menu item "Exposé & Spaces"
end tell
end tell
end tell
tell window "Exposé & Spaces"
tell tab group 1
click radio button "Exposé"
tell group "Active Screen Corners"
tell pop up button 1 -- top left corner
click
tell menu 1
click menu item "-"
end tell
end tell
delay 0.05 -- delay here to prevent error: "can't get menu 1 of pop up button 2 of group...invalid index"
tell pop up button 2 -- bottom left corner
click
tell menu 1
click menu item "-"
end tell
end tell
delay 0.05
tell pop up button 3 -- top right corner
click
tell menu 1
click menu item "-"
end tell
end tell
delay 0.05
tell pop up button 4 -- bottom right corner
click
tell menu 1
click menu item "-"
end tell
end tell

end tell
end tell
end tell
end tell
delay 0.1
keystroke "w" using command down
end tell

Unscripted Friday: Hot Corner Toggle On (Applescript)

File: togglehotcornerson.scpt
Language: Applescript
Download: http://gist.github.com/111945
Background: Hot corners, or active screen corners, are an option in OS X where you can toss your cursor to a corner to trigger an action, such as Expose, the launch of application, or the screensaver. However, this can take getting used to, and I'm reminded of this every time a visitor uses my notebook. To address this issue, I decided that I needed a one-click toggler to set and unset my four corners. GUI scripting via Applescript seemed to be the way to do it.

-- Hot Corner On Toggler:
-- Toggle all four hot corners on to specified settings
-- (assumes you've set the script to use predefined settings you always use.
-- This is the counterpart to the script that toggles all four hot corners off,
-- for cases when a visitor comes over who isn't used to active screen corners.
-- 2009 May 14. Written for OS X 10.5.x.
-- Gordon Mei, with guidance from Pierre L. from Apple discussions
-- Feel free to use and distribute however you'd like.

tell application "System Preferences" to activate
tell application "System Events"
tell process "System Preferences"
tell menu bar 1
tell menu bar item "View"
delay 0.5
tell menu 1
click menu item "Exposé & Spaces"
end tell
end tell
end tell
tell window "Exposé & Spaces"
tell tab group 1
click radio button "Exposé"
tell group "Active Screen Corners"
tell pop up button 1 -- top left corner
click
tell menu 1
click menu item "Spaces"
end tell
end tell
delay 0.05
-- delay here to prevent error: "can't get menu 1 of pop up button 2 of group...invalid index"
tell pop up button 2 -- bottom left corner
click
tell menu 1
click menu item "All Windows"
end tell
end tell
delay 0.05
tell pop up button 3 -- top right corner
click
tell menu 1
click menu item "Application Windows"
end tell
end tell
delay 0.05
tell pop up button 4 -- bottom right corner
click
tell menu 1
click menu item "Desktop"
end tell
end tell

end tell
end tell
end tell
end tell
delay 0.1
keystroke "w" using command down
end tell