Help with variable class?

Hi i’m doing a bit of scripting at the moment and i’ve got everything i want to work except the last detail…

I’m trying to get graphic converter to set the IPTC caption of an image i’ve loaded.

				
                               tell application "GraphicConverter"
					activate
					open target_file
					set ImageCaption to "TEST IT"
					set IPTC caption of window 1 to ImageCaption
					save window 1
					close window 1
					close saving yes
					
				end tell

if i set the iptc caption to a string of hardcoded text eg “abracadabra” it works fine
if i set a variable to a string of hardcoded text eg set ImageCaption to “abracadabra” and then the IPTC Caption to the variable, it works fine.

However what i’m trying to do is build a variable of a previous folder name (which i have in a variable) then $$ then the current file name then $$ then the system date eg “Folder_name$$filename$$ddmmyyyy”

When i build this variable and then set IPTC caption to it, it doesn’t work?

Has anyone any experience with this?

Any response appreciated.

Regards,
Dan

This works for me:


tell application "GraphicConverter"
	activate
	open alias "path to target"
	set ImageCaption to "FldrName" & "$$" & "Test" & "$$" & "17012007"
	set IPTC caption of window 1 to ImageCaption
	save window 1
	close window 1
end tell

Thanks for the reply.

The line you use would work for me as well.

The problem i have is that i have the details i want in the line in variables already eg:

ImageName = Name of doc i’m processing
CapDate = (month of (current_date)) & (year of (current_date))
CapIntro = name of folder of currently processing items

eg ImageName = “JD1NV1L07.eps”
CapDate = “0107”
CapIntro = “Cafe Noir”

but if i:

set ImageCaption to (CapIntro & “$$” & ImageName & “$$” & CapDate)

and then:

Set IPTC Caption of window 1 to ImageCaption

it just doesn’t work… ?

Would you post the code you’re actually using for these parts?

Taking that date part as is, I do not get “0107”:

set CapDate to (month of (current date)) & (year of (current date)) --> {January, 2007}
"$$" & result
--> "$$January2007"

AppleScript: 1.10.7
Operating System: Mac OS X (10.4)

Ok. Again thanks for the response.

Here is my script so far:

on adding folder items to this_folder after receiving these_items
	repeat with an_item in these_items
		set an_item to alias (an_item as text)
		set these_images to list folder an_item without invisibles
		
		if length of (an_item as string) is greater than 0 then
			if (an_item as string) contains ":To Process:" then
				set new_item to text 1 thru ((offset of ":To Process:" in (an_item as string)) - 1) of (an_item as string)
				
				set new_item to new_item & ":Processed:"
				set new_path to new_item
				set new_item to new_item & text ((offset of ":To Process:" in (an_item as string)) + 12) thru end of (an_item as string)
				set new_folder to text ((offset of ":To Process:" in (an_item as string)) + 12) thru end of (an_item as string)
			end if
		end if
		
		set new_item to text 1 thru ((length of new_item) - 1) of new_item
		set new_folder to text 1 thru ((length of new_folder) - 1) of new_folder
		
		if (new_folder as string) contains "_" then
			set image_code to text ((offset of "_" in (new_folder as string)) + 1) thru end of (new_folder as string)
			set new_folder to text 1 thru ((offset of "_" in (new_folder as string)) - 1) of (new_folder as string)
		end if
		
		set new_path to text 1 thru ((length of new_path) - 1) of new_path
		
		my create_folder(new_folder, new_path)
		
		set the target_folder to new_path & ":" & new_folder
		
		set cnter to 0 as number
		
		set yy to text 3 thru 4 of ((year of (current date)) as string)
		set mm to ((month of (current date)) as integer)
		
		if mm < 10 then
			set mm to ("0" & mm as string)
		end if
		
		repeat with an_image in these_images
			if an_image contains ".jpg" or an_image contains ".gif" or an_image contains ".eps" or an_image contains ".psd" or an_image contains ".CR2" or an_image contains ".tiff" or an_image contains ".tif" or an_image contains ".jpeg" or an_image contains ".bmp" then
				set image_path to an_item & an_image
				
				
				set cnter to cnter + 1
				set the doc_name to image_code & "L" & yy & cnter & ".eps"
				set the target_file to (target_folder & ":" & doc_name)
				set ImageName to (doc_name as Unicode text)
				
				tell application "Adobe Photoshop CS2"
					activate
					
					open alias (image_path as string) showing dialogs never
					
					do action "Auto Robot" from "Robot"
					save the current document in file target_file as Photoshop EPS with options {embed color profile:true, encoding:maximum quality JPEG, preview type:eight bit Mac OS}
					close current document saving no
					
				end tell
				
				try
					tell application "GraphicConverter"
						activate
						
						silentopen target_file
						set ImageCaption to new_folder & "$$" & ImageName & "$$" & mm & yy
						display dialog "TEST: '" & ImageCaption & "'"
						--set ImageCaption to "Hotel$$Product$$Date"
						set IPTC caption of window 1 to ImageCaption
						save window 1
						close window 1
					end tell
					
				end try
			end if
			
		end repeat
		
	end repeat
end adding folder items to

on create_folder(new_folder, new_path)
	tell application "Finder"
		if not (exists folder new_folder of (new_path as alias)) then
			make new folder at (new_path as alias) with properties {name:new_folder}
		end if
	end tell
end create_folder

I imagine it may be messy and there are probably better ways to do a number of the things i’m doing but i’m new to AS (tbh it seems overly convoluted)

Anyway.

If i swap in the commented hardcoded string it runs fine.

But as it stands the captioning fails and the only reason i can see is it must be something to do with the format of what i’m trying to put in it.

Cheers again, hope you can help.

Regards,
Dan

A nice clean way to get a short date time stamp is as follows:

set {year:y, month:m} to (current date) -- this construction appeared in Tiger.
tell (y * 100 + m) as string to set MMYY to text 5 thru 6 & text 3 thru 4

where the tell (y + m) as string part just avoids repeating it for each of the text parts later in the line.

Cheers for the helpful little tips with this guys, much appreciated.

However i’m still stuck on the main problem which is that if i insert a hardcoded string in my ImageCaption variable for the ‘Set IPTC Caption …’ bit it works but if i build up a string from variables it seems to fall over?

Hi drky,

You’re using the subroutine wrongly.

You need to set the variable to what is returned from the subroutine. The subroutine isn’t meant to change the variable passed to it (although it does that in certain situations).

I’ll have to look at the script again to make sure.

Edited: disregard this post. I thought new_folder was supposed to be a reference to the folder.

gl,

Cheers for the response though kel, nice to know i still have hope of a reply that’ll help :slight_smile: