![]() |
Set Location Via Applescript according to time of day?
Hi,
I use my laptop for college, and annoyingly we don't have an airport connection at college, so airport is off, and also there are different e'net settings, etc, etc. Basically, I have a Home profile, and a College profile. And rather than switch between the two manually all the time (i forget ;)), I decided today that I would use it to start to develop my interest in Applescript further. So far I have the time limiting set correctly for what i want to do. I'm calling SEC Helper as it imitates the mute key on the keyboard, and so when its restored at the end of the college day, its the same volume as the beginning (providing I haven't manually adjusted it of course). Here is the code I have so far: Code:
set c to (time of (current date)) / hoursCheers, Nemo |
Quote:
do shell script "/bin/sh read_volume.sh" |
Thanks. :)
The volume control was just an added idea, the main reason was wanting to change the location without having to GUI script to use the apple menu -> location. Was hoping that there was a way to script this so it could run in the background when activated by something along the lines of an app I saw recently that runs a script on the machine waking up. |
Why script location changes when you can make it automatic?
Open System Preferences -> Network -> Show "Network Port Configuration" and order the network ports in the order you want them. i.e put Airport first and then (I assume) Ethernet. Activate both. Set "Location" to automatic. Job done. If there's no Airport then the machine will try and use Ethernet. |
Doesn't turn airport off though so it still uses more battery power. Thats the main reason I want to automate the location switching. Plus I sometimes have to use a different ethernet connection at home compared to what I have the settings set to college, so I do actually need the two different locations.
Looks like I will have to just have the volume automated, and have to continue o remember to change the location. I suppose I could program in a dialog box that reminds me to change the location to the appropriate one according to the time. |
Try the "scselect" terminal command to script location changes. From AppleScript, it would look like:
do shell script scselect <location_name> |
My god that is so simple. Just what I was looking for. Thanks very much dave.
Afraid I need the commands for the volume read/write documenting in a bit more detail, but for now its off to the applescript site to see how to do that :) |
Wow, maybe you could get together with these guys and make some money:
http://homepage.mac.com/locationmanager/ |
Quote:
@iNemo. Unless there is some reason why you must use "SEC Helper", note that AS already has commands to change the volume. See the Standard Additions scripting dictionary under 'Miscellaneous' for details. |
I don't have any reason to use SEC Helper, except that was the command I found out and that started me thinking about such a script.
I will indeed look into the AS control of the volume as I'm sure its a bit more in depth than simply imitating the key press. PS. This is the script so far in case anyone is interested: Code:
-- Location changing script according to time. |
Getting Location Script a Little Closer
Quote:
Just a little fancier (a reporting dialog box):
|
Quote:
Code:
get volume settingsCode:
{output volume:100, input volume:100, alert volume:100, output muted:false} |
Quote:
Code:
tell (get volume settings) |
Looks like it should. Will test it at college later and let you know tonight. (I refuse to use the pc's at college to access the internet until the techies put the powerbook on the intranet :))
|
Appscrpt says: Where is SEC Helper?
Appscrpt says: Where is SEC Helper?
|
More
Also I cant save without telling Applescript.
|
Quote:
I use it because it imitates keys easily, although you can replicate this in system events (I think, I know you can replicate keys, presume volume keys are there as well.) You'd need to mess around with either getting system events to press the volume keys, or to use volume settings to change the system volume. |
The best way to switch AP on and off would probably be to piggypack on configd whenever it detects the plugging/unplugging of an ethernet cable.
To handle several locations, you could use the MAC-address of the default gateway. I wouldn't be surprised if there were already solutions existing based on that. |
The way I've got it setup is that I have a location with airport and ethernet not configured. It turns airport off, and kills all network traffic.
I'm not always plugged into an ethernet cable when I leave the network, so disabling airport on leaving ethernet doesn't always work. NB: If you look at the date of the first post here, I actually started this last year sometime. When my HD crashed and burned I lost all the code, so I'd forgotten all about this. Now I've got time this summer I'll have to play with it again. |
Quote:
Have a look at these macosxhints articles for starters: http://www.macosxhints.com/article.p...60122060330816 http://www.macosxhints.com/article.p...05010613401823 http://www.macosxhints.com/article.p...40923133938271 |
Salling Clicker costs how much?
|
Can I not use Salling Clicker?
|
Quote:
It costs $23.95 according to the webpage http://salling.com/Clicker/mac/ |
| All times are GMT -5. The time now is 05:41 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.