Automating Script Creation

Hi there I have a list of lists. Each item in the list contains 2 items. I want to explore the possibility of writing a script for each top level item using the 2 enclosed items as variables to enter into each script, eg

Item 1
Item 1 “developer name”
Item 2 “product name”
Etc…

Then if possible iterate through the list creating a script like the one below for each item

Set devName to “developer name”
Set plugName to “product name”

Tell script “auSel”
          auSel(devName, plugName)
End tell

Then save the script as a scpt with the name of the current variable plugName into my home scripts folder. Is this possible?

The script below should do what you want. Basic idea is to loop over your list of pairs, and for each: build a text version, write a temp text file, then compile that to your desired destination folder.

-- Here is a sample list of devName/plugName pairs::
set pairList to {{"developer fake1", "product fake1"}, {"developer fake2", "product fake2"}}

-- pick a folder in which to save the compiled .scpt files 
-- (this sample code assumes you have a "Scripts" folder in your user's Home folder):
set targetFolderPath to ((path to home folder) as string) & "Scripts:"

-- loop over your list of devName/plugName pairs:
repeat with onePair in pairList
	set onePair to contents of onePair
	
	-- pull out the pair values:
	set devName to item 1 of onePair
	set plugName to item 2 of onePair
	
	-- construct a text version of the script code using this pair:
	set myScriptCode to "set devName to \"" & devName & "\"
set plugName to \"" & plugName & "\"
tell script \"auSel\"
	auSel(devName, plugName)
end tell
"
	
	-- write the modified code into a temporary ".applescript" (text) file:
	set pathTempCode to ((path to temporary items) as string) & plugName & ".applescript"
	set fileRef to (open for access file pathTempCode with write permission)
	set eof of fileRef to 0 --> empty file contents if needed
	write myScriptCode to fileRef
	close access fileRef
	
	-- COMPILE the temp/text file to the desired destination:
	set pathCompiled to targetFolderPath & plugName & ".scpt"
	do shell script "osacompile -o " & quoted form of POSIX path of pathCompiled & " " & quoted form of POSIX path of pathTempCode
end repeat

Thanks Krioni,

I’ll check out your method
Was working on a script whilst you were sending that. Managed to suss it out»…


set au_comp to get value of every text field of every row of table 1 of scroll area 2 of splitter group 1 of window "Plug-In Manager" of application process "Logic Pro X"

set exBus to {}
repeat with i from 1 to count of au_comp
	set au_comps to item i of au_comp
	set au_name to the fifth item of au_comps
	set au_dev to the first item of au_comps
	set au_type to the fourth item of au_comps
	
	
	set end of exBus to {au_type, au_name, au_dev}
end repeat


set theList to {}
repeat with i from 1 to count of exBus
	
	set aList to item i of exBus
	
	set theDev to the second item of aList
	set thePlug to the third item of aList
	set theTag to the first item of aList
	set trackPath to "~/Desktop/tests/trackFx/" & quoted form of thePlug & ".scpt" as text
	set busPath to "~/Desktop/tests/theBusFx/" & quoted form of thePlug & ".scpt" as text
	set instPath to "~/Desktop/tests/" & quoted form of thePlug & ".scpt" as text
	set instScript to "use AppleScript version \"2.4\" 
	use scripting additions
	tell application \"System Events\" to tell process \"Logic Pro\"
		set tracks_window to title of first window whose title contains \"- Tracks\"
		set frontmost to true
	end tell
	
	set devLab to " & space & quote & theDev & quote & "
	set plugName to " & space & quote & thePlug & quote & "
	tell script \"selInst\"
		selInst(devLab, plugName)
	end tell"
	
	set trackScript to "use AppleScript version \"2.4\" 
use scripting additions
set devLab to " & space & quote & theDev & quote & "
set plugName to " & space & quote & thePlug & quote & "
tell script \"trackFx\"
	trackFx(devLab, plugName)
end tell"
	set busScript to "use AppleScript version \"2.4\" 
use scripting additions
set devLab to " & space & quote & theDev & quote & "
set plugName to " & space & quote & thePlug & quote & "
tell script \"theBus\"
	theBus(devLab, plugName)
end tell"
	set cList to every item of aList
	if the first item of cList contains "instrument" then
		do shell script "echo " & quoted form of instScript & " | osacompile -o " & instPath
		
		delay 0.2
		do shell script "/usr/local/bin/tag -a " & "'" & theDev & "'" & space & instPath 
		
		do shell script "/usr/local/bin/tag -a " & "'" & theTag & "'" & space & instPath
		
	else
		do shell script "echo " & quoted form of trackScript & " | osacompile -o " & trackPath
		delay 0.2
		do shell script "/usr/local/bin/tag -a " & "'" & theDev & "'" & space & trackPath 
		
		do shell script "/usr/local/bin/tag -a " & "'" & theTag & "'" & space & trackPath 
		
		
		
		do shell script "echo " & quoted form of busScript & " | osacompile -o " & busPath
		delay 0.2
		do shell script "/usr/local/bin/tag -a " & "'" & theDev & "'" & space & busPath 
		
		do shell script "/usr/local/bin/tag -a " & "'" & theTag & "'" & space & busPath
	end if
	set end of theList to aList
end repeat