Archive for the ‘applescript’ tag
Using Quicksilver to edit hosts file
This is mostly just a follow up for my previous post on using a shell script to add and remove test domains in the hosts file. I have created two small applescripts for use in Quicksilver to execute that script. If you need to use these you place them in ~/Library/Application Support/Quicksilver/Actions and set your password. (Beware this could pose a threat, since you will have your password in cleartext on your harddrive).
The two scripts are almost identical. Actually the only difference is the action the shell script should call (add or remove). The rest of the scripts are completely the same.
I call this file addhost.
using terms from application "Quicksilver" on process text txt set the_password to "YOURPASSWORD" repeat with delimiter_position from 1 to (length of txt) if character delimiter_position of txt = " " then exit repeat end repeat if delimiter_position = (length of txt) then set hostname to txt as string set ipaddress to "" else set hostname to characters 1 thru (delimiter_position - 1) of txt as string set ipaddress to characters (delimiter_position + 1) thru (length of txt) of txt as string end if do shell script "sudo hosts.sh add " & hostname & " " & ipaddress password the_password with administrator privileges return nothing end process text end using terms from
I call this file removehost.
using terms from application "Quicksilver" on process text txt set the_password to "YOURPASSWORD" repeat with delimiter_position from 1 to (length of txt) if character delimiter_position of txt = " " then exit repeat end repeat if delimiter_position = (length of txt) then set hostname to txt as string set ipaddress to "" else set hostname to characters 1 thru (delimiter_position - 1) of txt as string set ipaddress to characters (delimiter_position + 1) thru (length of txt) of txt as string end if do shell script "sudo hosts.sh remove " & hostname & " " & ipaddress password the_password with administrator privileges return nothing end process text end using terms from
Now I am able to create a local domain by opening Quicksilver (double-control in my case) press period, write the domain name, press tab, and select the addhost action (ad is enough in my case). Removing is just as easy – the last step is just to select the removehost action (re is enough in my case).
Resizing Itunes Window with Applescript
This weekend my girlfriend and I moved all the stuff I had in my private office/homestudio out, to create a room for our son. Because of this my old mac was put in the living room, and is now a primitive media center with the TV as it’s only screen. The resolution as a result has changed to something significantly lower, and there are no longer two screens. As a result the Itunes window was too big, and I was not able to resize it, since the area where this is possible was outside the viewable area of the screen, no mather what I did.
I decided it was time for some AppleScript to solve this problem.
tell application "iTunes"
set bounds of window 1 to {1, 1, 400, 400}
end tell
ps – had an old cordless windows keyboard and mouse – it is a bit weird trying to figure out which keys do what…