Scripting

Swinsian supports scripting with Applescript. It is possible to get information about the current track and control playback.

Controlling playback

tell application "Swinsian"

	-- basic playback controls
	play
	pause
	stop

	-- toggles playback if paused and vice versa
	playpause

	-- skipping
	next track
	previous track

end tell

Getting info about tracks

tell application "Swinsian"

	-- get the currently playing track
	set thetrack to current track

	-- get properties of the track
	set trackname to name of thetrack
	set trackartist to artist of thetrack
	set trackalbum to album of thetrack

	set info to "You are listening to " & trackname & " by " & trackartist & " on " & trackalbum

end tell

Working with playlists

tell application "Swinsian"

	-- get the first playlist
	set thepl to first playlist

	-- get the name of the playlist
	set thename to name of thepl

	-- find out how many items in the playlist
	set thecount to count of tracks of thepl

	-- check that the playlist is not a smart playlist
	-- then add the current track to the playlist
	if not (smart of thepl) then
	add tracks (current track as list) to thepl
	end if

	-- finding tracks in a playlist
	set foundtracks to search playlist thepl for "Dylan"
end tell

Examples

Numbering the selected tracks:

tell application "Swinsian"
	set selected to selection of window 1

	if selected is not {} then
		set c to count of selected's items

		repeat with i from 1 to c
			set tr to item i of selected
			set the track number of tr to i
		end repeat
	end if
end tell