AppleScript


I’m trying to create reference movies (as Quicktime .MOV documents) for all of the movies on my Media server, and the most obvious method is to use AppleScript and Quicktime Player. Why am I doing this? Because iTunes requires Quicktime Movies, I’ve mainly got AVIs, and I don’t want to (a) convert all of them, and (b) have iTunes manage them. I’d rather have the files in the right spot, and allow iTunes to manage the reference movies.

Quicktime will often open files of varying types, even though iTunes will not. It’s then possible to save the file, and choose not to create a stand-alone movie. This will create a reference movie, which is much smaller than the original, but requires that the original remains in the same place in order to work.
(more…)

View Comments (6)   RSS Feed for Comments on this Post

I like that iTunes displays half-star ratings, but I want my tracks rated 51-59 to display this way too. That doesn’t work, but if you use the following script, it will round the ratings of selected tracks to the nearest half-star:

tell application "iTunes"
	repeat with trk in selection
		set rating of trk to ((rating of trk) / 10 as integer) * 10
	end repeat
end tell

I hope Apple don’t include the functionality of odd-rated tracks to play different amounts, otherwise I’ll need to re-rate all of my music. Again.

View Comments (0)   RSS Feed for Comments on this Post

My biggest hate about iTunes is that if the download of a Podcast fails, it needs to restart the whole download, rather than just resume. This really sucks if you are 21Mb into a 22.5Mb download.

Using the technique illustrated in Adding a Podcast to a Pre-Existing Subscription, it’s possible to download the files in another program, such as wget, which can handle resumes. It also tends not to drop out as much as iTunes does when the network is congested. Which it is automatically when three downloads are concurrently occurring.

There are some changes that need to be made to the process, but these are really just simplifications. You need to know the URL of the file you want to get, which can be obtained using the following AppleScript:

tell application "iTunes"
    set the clipboard to address of item 1 of selection
end tell

Then, set up your http server, and create the same directory structure from your server root. Go to the relevant directory, and download the files you want to grab.

Finally, go offline, and point the domain(s) at your own computer. Go back into iTunes, and use the GET button to grab the files from your own ’server’. Don’t use the Update Podcasts button, or an error may occur.

This removes the need to recreate the XML file, which is the most labour intensive part of the process illustrated in the previous post. It works a treat.

View Comments (0)   RSS Feed for Comments on this Post

From OmniNerd: Playing Favourites, I decided to run my own version of the experiment that compares how often songs with different ratings get played by iTunes.

The difference with my experiment is that it has 101 tracks, each with a different rating (0, 1, …, 99, 100).
(more…)

View Comment (1)   RSS Feed for Comments on this Post

I’m trying to save time by creating some simple scripts to add values to Address Book entries. For instance, I have a whole lot of people in a group who are living in the same state, and I want to add this to all addresses.

However, it doesn’t seem to be possible to get or set the state of an address:

tell application "Address Book"
	tell my card
		set the_state to state of address 1
	end tell
end tell

This fails. With the very helpful:

Address Book got an error: Can’t make state of address 1 of my card into type reference.

Which means absolutely nothing, as far as I can. Googling this string brings no joy.

Now the weird thing is that if I switch over to another user, it works fine.

Update: I quit all running Apps (with the intention of restarting, but System Update stopped me) and retried it. It worked. Something I was running was interfering with it, but I have no idea what.

View Comments (0)   RSS Feed for Comments on this Post

This looks promising. Shark is a tool that can be used to profile code. I haven’t done any serious profiling since some python script I was working on years ago on BeOS.

Daniel Jalkut has a nice post, Shark Bites Script up on his blog, on how to use Shark to profile AppleScript code. Since I’ve been doing a bit of AppleScripting lately, and I have some code that is in serious need of optimisation, this might be worth a second look.

View Comments (0)   RSS Feed for Comments on this Post

I wrote my own script to convert the selection (or whole front document) in Script Editor to XHTML. It uses the same CSS tags as Jonathon’s program, but does not add the style data in, unless a property is set.

I’ve also got the Source Code for his program, so it will be interesting to see similarities.
(more…)

View Comments (0)   RSS Feed for Comments on this Post

Since I need to replace all ” in the generated XHTML with ‘, I use the replace function from the previous post.

(*
Bugs:

Does not like no selection: no real way to get the selection from SEE anyway.
Sometimes does not execute if called from Script Menu.  Intermittant.
*)

-- If called from Script Menu, need to do this.

tell application "SubEthaEdit"
	activate
	tell application "System Events" to keystroke "C" using {command down}
end tell

set theStart to (the clipboard)

set the clipboard to (my replace(theStart, "\"", "'"))

beep

-- Another way of the Replace Function being called:

-- set the clipboard to (replaceText from theStart to "'" instead of "\"")

on replace(theText, find, replace)
	set OldDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to find
	set newText to text items of theText
	set AppleScript's text item delimiters to replace
	set theResult to newText as text
	set AppleScript's text item delimiters to OldDelims
	return theResult
end replace

-- Alternate version of replace()

to replaceText from theText to replace instead of find
	set OldDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to find
	set theText to text items of theText
	set AppleScript's text item delimiters to replace
	set theText to theText as text
	set AppleScript's text item delimiters to OldDelims
	theText
end replaceText

View Comment (1)   RSS Feed for Comments on this Post

I like to present styled code for my readers, but I’m not totally happy with my methods of getting it: SubEthaEdit’s Export as XHTML is very cool, but I still have to tweak it so it looks nice. And I’ve got a great program for getting the XHTML version of the code Script Editor (AppleScript) is currently displaying.

But, I’d like more flexibility. I want the code to be tagged with classes, like it’s possible to do with the Script Editor add-on, rather than using inline styles. I’ve already done this for the Script Editor code, but I just need to remember to remove the inline stylesheet from the start of the generated code. Unfortunately the Script has been saved as a Run Only.

I’d love to know a way to decompile one of these Scripts…apparently there isn’t. I’ll have to write my own. Or see if Jon is nice enough to give the Source Code.

As for the SubEthaEdit part: I should be able to do it. I’ve learned a couple of tricks that will help.

View Comments (0)   RSS Feed for Comments on this Post

I used to use ecto to paste all of my entries on my blog, but with Blogsome’s XMLRPC issue, I have to use a browser. But it would be nice to automatically get the name and information about my currently playing iTunes track, just like ecto used to do.

I wrote an AppleScript that does this, and, inserts the data in at the insertion point for you.

Because it’s intended to be run from the Script Menu, and everything run from there runs as “System Events”, I had to hard code in the browser name. If you use another browser, just replace the second line with whatever your browser is called.
(more…)

View Comments (0)   RSS Feed for Comments on this Post

« Previous PageNext Page »