Log in

applescript [entries|archive|friends|userinfo]

[ website | Apple's AppleScript Home Page ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

another alarm script [Dec. 23rd, 2008|03:15 pm]

In energy preferances i have my computer wake up everyday at 8:00.  I run the following script everytime the computer starts.  If it's after 8:30am it does nothing. otherwise we play the music in iTunes.  Then check if the ethernet connection is available (I often turn off my modem at night) if not switch to a pre-defined network configuration('roaming') that uses wifi and wait till there is a connection. Then allow some time for mail to download.  By now I should be awake and can turn on my modem so switch back from wifi to my dsl connection('Automatic').  

 if (current date)'s time < 30600 then

set volume output volume 85

tell application "iTunes"

set sound volume to 85

play playlist "wake"

end tell

if (do shell script "ifconfig en0 | awk '/inet/ {print $2}'") is equal to "" then

do shell script "scselect roaming"

repeat until (do shell script "ifconfig en1 | awk '/inet/ {print $2}'") is not equal to ""

end repeat

tell application "Thunderbird"


end tell

delay 120

do shell script "scselect Automatic"


tell application "Thunderbird"


end tell

end if

end if

linkpost comment

Dock Indicator / Asynchronous Scripting [Nov. 28th, 2008|03:02 am]

I just had a little "ah-ha!" moment I'd like to share.

I'm always looking for new and lazier ways to do user interaction that don't involve display dialog or third party software. My brilliant idea today is to use the launch app command to unobtrusively start a stay-open script app that contains a reopen handler which quits itself. Pseudocode:

Script app 1:
on idle: if itunes is shuffling then launch app 2
on reopen: tell itunes to shuffle, launch app 2

Script app 2:
on reopen: tell itunes to stop shuffling, tell me to quit

The point of this is if iTunes is shuffling, app 2 will magically appear in my dock. Clicking app 1's dock icon will also cause this to happen. If app 2's icon is visible, I can click it to dismiss the indication and reset iTunes' shuffle state. I like the idea because it lets me cue up a bit of code in such a way that I don't have to deal with it right now to keep the app 1 idler happy. In the past I found use for this behavior with asynchronous scripts in shell. App 2 could even be written to fetch a property from app 1 without app 1 having to explicitly pass it as a parameter.
linkpost comment

About iMovie Launcher Script Problem [Nov. 5th, 2008|02:28 pm]

I have a script I use to launch iMovie HD.
If I launch the program with both Perian and the Eye TV MPEG Component loaded, it causes import problems. But if one is disabled when the program is launched, even if it's then re-enabled right away, iMovie works fine.

It's saved as an app that I launch from the Dock.

The script changes the name of Perian.component to Perian.txt and then back.

Code Behind CutCollapse )

I've found that at times, it gives an error message and fails to change the name back.

Free Image Hosting at www.ImageShack.us

It seems that if I have the Quicktime folder open, it doesn't happen or that if I run the script from Script Editor it doesn't. These aren't consistent though (right now, with neither the editor nor the window open, I don't get the error).

I could add lines to open and close the window during the script, but surely there's a better solution to use (or at least a reason).
link5 comments|post comment

Is this community still alive? [Nov. 4th, 2008|01:33 pm]


Is this place still alive, or has discussion migrated elsewhere?
link2 comments|post comment

What desktop is currently displayed? [Dec. 17th, 2007|01:32 am]

Do you use a folder of images for your desktop picture?  Have it on Random and too many images to locate an interesting/offensive image?  Have multiple monitors (or not)?  How do could we find the images quickly?

First, set the view of each folder to list and include Label as a column sorting descending (triangle down).  Next, use this handy script to locate the images.

 I suggest using this either in the script menu or as an app launched from a folder kept on the dock.

linkpost comment

Too many Wikipedia and 4chan images... [Dec. 13th, 2007|01:44 am]

I have a large collection of images I've acquired from various sources around the internet.  Too many to find any one in a reasonable amount of time.  I've tried Graphic Converter's quick move folders, smart folders within OS X, and manually creating folders as I found new categories to sort and sub/sort.  None of these were effective or very fast.

Applescript to the rescue!  Here's a little script I wrote that if saved as an application to be placed in the dock or a finder plugin may save you time by either adding a "tag" to the "Get Info" comment (which is spotlight friendly) or sending the files to a new/existing folder within the same folder you're looking in.  Do have fun with it!


--Edit - Various corrections and optimizations

linkpost comment

Minimize all windows [Aug. 29th, 2007|05:39 pm]

I want to minimize all opened windows by script:

repeat with w in (get every window)
set miniaturized of w to true
end repeat

But it only minimizes an apple script editor windows. Can anybody help me?

UPD: i got it)))
on run
tell application "System Events"
set visible of every process whose visible is true and name is not "Finder" to false
end tell
end run

on FinderCheck()
tell application "System Events"
if (name of every process) does not contain "Finder" then
tell application "Finder" to launch
end if
end tell
end FinderCheck
link13 comments|post comment

Unscriptable Numbers [Aug. 8th, 2007|03:53 pm]


The latest member of the iWork suite does not feature AppleScript support. The other two apps debuted without support but it was added a year or so later by paid upgrade. I had to do some hacking at the Apple store to work this out as they hadn't installed iWork on the demo machines yet and they wouldn't let me install the trial version. I did however manage to examine the binary in the package and determined it lacked a dictionary, then confirmed this when I got home. I'll probably wait a while longer before I make a decision whether to buy it anyway. Are you planing to upgrade? Are you annoyed that Apple keeps shipping dictionary-less apps?
linkpost comment

applescript and system preferences [Jul. 26th, 2007|11:13 am]

Hi, I just joined because I'm somewhat desperately in search of some Applescripting help. I'm pretty new to Applescript, but I've been picking it up pretty quickly as I go.

I'm trying to write a little application in Xcode that uses Applescript to do its thing. Basically, I work at a university and we manage all of the teaching classrooms that contain computers for lectures and so on. There are roughly 60 of them, and most of them contain Macs. Every year, we go around and reinstall OS X from a custom-made DVD with all our standard software pre-installed and so on. After that, we have to set up each Mac's individual network settings (IP, DNS, etc...). What I've been working on creating is an Applescript that will open the Network settings in System Preferences and change the TCP/IP settings after a room name is selected from a pulldown menu. However, I am having trouble actually getting the Applescript to be able to modify the text in the fields to change the IP address and other settings. I have gotten as far as scripting the Network window to open when a button is clicked, but beyond that I can't do much.

I've been scouring the internet looking for instructions on how to do this, and I've come up empty handed. While I've learned a lot about Applescript in general, I haven't yet found anything that can explain to me how to make a script change things in text fields. Can someone help me figure out how to do this, if it's even possible at all? Thank you!
link7 comments|post comment

Data types and iTunes [Jun. 11th, 2007|08:43 am]
1) What I'm doing
The implementation of the CD Info databases iTunes uses seems frequently quite poor. Occasionally it's actually gone so far as to screw up any audio program using it so that it doesn't know there's a disc inserted, necessitating redoing it... Plus most of my audio collection is audiobooks -- some on physical bought cds, some ripped from Audible or audio tape onto my backup cds.

I'm trying to implement my own personal-use equivalent of the databases in XML--after all, I know what book the disc I've inserted belongs to, so I don't want a 'CD Info' style database of every disc ever imported or burned (or, worse, every disc someone's ever had through CDDB).  Especially since CD Info is broken to the extent that if you ever insert an audio CD with a single long track (like a track that may have been burned from an Audible download or an audio tape or podcast to be cut into tracks later), it will then match it to the last 'long single track' cd you inserted, even if the track lengths are different, and I know I'm not the only one this has happened to, because the Toast forums are full of complaints from people who get the CDDB info from 'some random gapless CD' or some CD which happens to match the details among thousands and thousands of CDs.

So what I want is for the script to look through details for between 3 and 10 discs at a time, typically (on the principle that it's less fragile than trying to check thousands at a time). I get the data by writing it out to file when it's correct (using the excellent XMLLib osax to get the data into a file). Then I've got it on file if the CD info breaks yet again and has to be rebuilt.

2) The Problem

I think I've got it to work, but why am I getting a problem with spurious differences between the track lengths written out to XML and the track lengths in iTunes when they look the same. I get the track length of the track from the XML file (in a 'length' tag) and it looks like "217.345993041992". I get the 'duration of aTrack' from iTunes, and that also looks just like "217.345993041992". Both of those should be values in seconds, presumably real, or able to be coerced thereto, but when I check for equality using both values as real, they don't match (and if I subtract one from the other I get some spurious value). I'm checking both values 'as string', which works, but why wouldn't it work as real, because both values are in seconds and real rather than integer?
link6 comments|post comment

[ viewing | 10 entries back ]
[ go | earlier/later ]