View Single Post
Here's a little script that will prompt for a key name and value and add them to the user data of every object in your document. Then you can put things like

Code:
Document prepared for <%userdata ClientName%>
in your document, and update them whenever needed by simply running the script again. Note: user data keys cannot have spaces in them, so "Client Name" won't work, but "ClientName" will.

Thanks to RobTrew for showing the way to someone so unwilling to actually sit down and learn Applescript properly :-)

Code:
tell application id "OGfl"
	set MykeyName to my PromptKeyInfo("Name of key to create/set", "MyKey", false)
	set MydataVal to my PromptKeyInfo("Value of data to set", "<None>", true)
	
	
	set MyScript to "
tell application id \"OGfl\"
	repeat with aCanvas in every canvas of document of front window
		set canvas of front window to aCanvas
		
		repeat with aGraphic in every graphic of aCanvas
			if (count of user data of aGraphic is not 0) then
			    set user data of aGraphic to {" & MykeyName & ":\"" & MydataVal & "\"} & user data of aGraphic
			else
			    set user data of aGraphic to {" & MykeyName & ":\"" & MydataVal & "\"}
			end if
		end repeat
	end repeat
end tell
"
	
	run script MyScript
end tell

on PromptKeyInfo(Prompt, DefaultAnswer, SpacesAllowed)
	set Successful to false
	repeat while (Successful is not true)
		set recReturned to display dialog Prompt default answer DefaultAnswer buttons {"OK", "Cancel"} default button {"OK"}
		set retVal to (text returned of recReturned)
		set Successful to true
		if (not SpacesAllowed) then
			set tid to AppleScript's text item delimiters
			set AppleScript's text item delimiters to " "
			set wordCount to count of every text item of retVal
			if (wordCount is not 1) then
				display dialog "Key names may not contain spaces"
				set Successful to false
			end if
		end if
	end repeat
	return retVal
end PromptKeyInfo
Attached Files
File Type: zip Populate user data.zip (3.8 KB, 615 views)