🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #20663

Re: AppleSript: From Toast/iTunes to InDesign

#20663
From: Kari Puikkonen
Date: Mon, 01 Jul 2002 16:39
91 lines
4032 bytes
Part II 

The second script exports iTunes playlist - via clipboard, pastes it to InDesign and formats the resulting text frame. You need to have InDesign document open with one empty text frame (for example 11 cm x 11 cm, so you can use the result as CD cover), which does not need to be selected.  
You also  need two paragraph styles; "Title" and "Songs", which you can format beforehand to your own taste (for example to the kind of which you can use as a CD cover). 
Before running this script I recommend that you run "Number Tracks of Playlist" by Doug Adams (http://www.malcolmadams.com/itunes/ ), so that you get also the track numbers. 

property summary_options : {"Song � Time"} 
property summary_type : (item 1 of the summary_options) 

tell application "iTunes" 

	set the delimiter_character to "   " 

	--the playlist currently selected is the one that will be copied 
	set this_playlist to the view of browser window 1 
	set this_name to (the name of this_playlist) as string 

	if the summary_type is item 1 of the summary_options then 
		--loop through each track and retrieve song title and time information 
		set the playlist_count to the count of tracks of this_playlist 
		set playlist_data to {this_name} & return & return 
		tell this_playlist 
			repeat with i from 1 to the count of tracks 
				tell track i 
					set the end of the playlist_data to {name, delimiter_character, time, return} 
				end tell 
			end repeat 
		end tell 
	end if 

end tell 

tell application "Finder" 
	activate 
	set the clipboard to (playlist_data) as text 
end tell 

tell application "InDesign 2.0.1" 

	--Get a reference to a text frame   
	set myTextFrame to text frame 1 of page 1 of active document 
	set myStory to parent story of myTextFrame 
	set myInsertionPoint to insertion point 1 of myStory 

	tell document 1 

		--Select the insertion point  
		select myInsertionPoint 
		paste 

		set theSongs to paragraph style "Songs" 
		set theTitle to paragraph style "Title" 

		tell text frame 1 
			tell parent story 
				repeat while (get character -1) = return 
					delete character -1 
				end repeat 
				set applied paragraph style of paragraphs to theSongs 
				set applied paragraph style of paragraph 1 to theTitle 
				set theOffset to index of paragraph 2 
			end tell 
			set startTrack to -1 
			set endTrack to -20 
			repeat while (get overflows) is true 
				set tracking of parent story to startTrack 
				set startTrack to startTrack - 1 
				if startTrack = endTrack then 
					exit repeat 
				end if 
			end repeat 
			set startSize to 11 
			set endSize to 7 
			repeat while (get overflows) is true 
				set point size of text from character theOffset to character -1 of parent story to startSize 
				set startSize to startSize - 0.25 
				if startSize = endSize then 
					exit repeat 
				end if 
			end repeat 
		end tell 
	end tell 
end tell 

Have a fun! 

P.S. I don't know whether these scripts are useful to anybody, but while banging my head with these I learned a bit more about making AppleScripts... 

P.S. 2 I like hear comments/opinions about if it is possible to make these scripts faster/smarter/clever... 

Kari
Technical Details
Message-ID: <ef96c33.0@WebX.aaQKaf7vad4>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!64.152.100.70.MISMATCH!ps01-sjc1!news.webusenet.com!cyclone.bc.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <ef96c33.-1@WebX.aaQKaf7vad4>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f939a,78322622044f6402
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2002-07-01 10:10:21 PST
From: "Kari Puikkonen" <kari.puikkonen@welho.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!64.152.100.70.MISMATCH!ps01-sjc1!news.webusenet.com!cyclone.bc.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: AppleSript: From Toast/iTunes to InDesign
Message-ID: <ef96c33.0@WebX.aaQKaf7vad4>
Date: Mon, 1 Jul 2002 09:39:31 -0700
References: <ef96c33.-1@WebX.aaQKaf7vad4>
Lines: 105
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit