another file/creator type issue

howdy all,

i am trying to make a drag-n-drop script that will change the file/creator type for the dropped file chosen from a list by the user. the list part works fine, but change part doesn’t. i get the error “can’t make some data into the expected type.”

what am i missing?!

here’s what i’ve got; i truncated the choices down to one for this example:


property FileType : ""
property CreatorType : ""

on open theFiles
	tell application "Finder"
		activate
		
		set pickProgram to choose from list {"Plain TXT"} with prompt ¬
			"What kind of file should this be?"
		
		set button_name to pickProgram
		
		if button_name is "Plain TXT" then
			set FileType to "ttxt"
			set CreatorType to "TEXT"
		end if
		
		repeat with eachFile in theFiles
			set the file type of eachFile to FileType
			set the file creator of eachFile to CreatorType
		end repeat
		
	end tell
end open

thanks in advance for any help!
ray.

Hi,

I used to get this mixed up sometimes also. The record returned by the ‘info for’ command has ‘file creator’ as a label, while the “Finder” uses ‘creator type’.

You might want to double check on your ‘file type’ and ‘creator type’ for text files.

gl,

Hey Kel,

thanks for the help! you were right, i had the variables for the creator/file type backwards. i switched them around but unfortunately i’m still getting the same error message. i also tried changing ‘file creator’ to ‘creator type’ to no avail.

i’ve been using this line to get the creator/file type data:


{file creator, file type} of (info for (choose file))

is there a better way (this way seems a bit buggy – sometimes the files return empty records)

thanks again
ray.

Hi,

Further up. Choose from list returns a list, so the comparison:
button_name is “Plain TXT”

is never true. I don’t think you can change the types to less than 4 character unless the file is created without types.

gl,

Further up. Choose from list returns a list, so the comparison:
button_name is “Plain TXT”

is never true. I don’t think you can change the types to less than 4 character unless the file is created without types.

hey Kel,

not sure what you mean – there WILL be a list of items to choose from, i just truncated it down to the one so the example would be less confusing (i thought…), and the current configuration does return “Plain TXT” as a result.

Ray:

Kel is correct. The Choose From File returns a list as its result. You then push this list into the variable button_name. The you try to compare button_name (a list) to “Plain TXT” (which is a string). So button_name (as it stands) will NEVER resolve to “Plain TXT” because you’re comparing apples to oranges.

A simple fix would be to say…

if (button_name as string) = “Plain TXT” then…
coercing the list to a string.

Best Regards,
Jim Neumann
BLUEFROG

Hey Jim, thanks…

so, what you guys are saying is that even though it only returns one answer, even when i have a full list of options, that answer is STILL considered a list and needs to be text? that finally made sense after i realised that the result was set in brackets rather than just quotes…

i incorporated your suggestion and it appears to be working (it doesn’t error out, anyway…)

here’s copy of the full script as it is now:


property FileType : ""
property CreatorType : ""

on open theFiles
	tell application "Finder"
		activate
		
		set pickProgram to choose from list {"Quark 5", "Quark 6", "InDesign", "Illustrator AI", "Illustrator EPS", "Illustrator PDF", "Acrobat PDF", "Photoshop PSD", "Photoshop TIFF", "Photoshop JPEG", "Photoshop GIF", "Photoshop EPS", "Word DOC", "Word RTF", "Plain TXT"} with prompt ¬
			"What kind of file should this be?" OK button name "Go Man" cancel button name "Nevermind"
		
		set pickProgram to buttonResult
		
		if (buttonResult as string) = "Quark 5" then
			set FileType to "XDOC"
			set CreatorType to "XPR3"
			
		else if (buttonResult as string) = "Quark 6" then
			set FileType to "XPRJ"
			set CreatorType to "XPR3"
			
		else if (buttonResult as string) = "InDesign" then
			set FileType to "IDd4"
			set CreatorType to "InDn"
			
		else if (buttonResult as string) = "Illustrator AI" then
			set FileType to "PDF "
			set CreatorType to "ART5"
			
		else if (buttonResult as string) = "Illustrator EPS" then
			set FileType to "EPSF"
			set CreatorType to "ART5"
			
		else if (buttonResult as string) = "Illustrator PDF" then
			set FileType to "PDF "
			set CreatorType to "ART5"
			
		else if (buttonResult as string) = "Acrobat PDF" then
			set FileType to "PDF "
			set CreatorType to "CARO"
			
		else if (buttonResult as string) = "Photoshop PSD" then
			set FileType to "EPSF"
			set CreatorType to "8BIM"
			
		else if (buttonResult as string) = "Photoshop TIFF" then
			set FileType to "TIFF"
			set CreatorType to "8BIM"
			
		else if (buttonResult as string) = "Photoshop JPEG" then
			set FileType to "JPEG"
			set CreatorType to "8BIM"
			
		else if (buttonResult as string) = "Photoshop GIF" then
			set FileType to "GIFf"
			set CreatorType to "8BIM"
			
		else if (buttonResult as string) = "Photoshop EPS" then
			set FileType to "EPSF"
			set CreatorType to "8BIM"
			
		else if (buttonResult as string) = "Word DOC" then
			set FileType to "W8BN"
			set CreatorType to "MSWD"
			
		else if (buttonResult as string) = "Word RTF" then
			set FileType to "W8BN"
			set CreatorType to "MSWD"
			
		else if (buttonResult as string) = "Plain TXT" then
			set FileType to "ttxt" as text
			set CreatorType to "TEXT" as text
		end if
		
		repeat with eachFile in theFiles
			set the file type of eachFile to FileType
			set the file creator of eachFile to CreatorType
		end repeat
		
	end tell
end open

now my only issue, aside from actually proving that it does what it should (G), is that the SECOND time it runs i get an error saying “the variable buttonResult is not defined”. the THIRD time is fine again, etc. what gives!?

thanks
ray.

Ray:

I don’t know why you’re getting sporadic result - mine errored immediately on an undefined buttonresult.

A few things…

  1. You set pickprogram to choose from list - then you set pickprogram to buttonresult. At this point buttonresult IS undefined (hence the error I received.) You need to swap them - set buttonresult to pickprogram. But… You don’t even need buttonresult. Pickprogram carries the value you need (in a list) so there’s no sense in pushing into another variable. Replace buttonResult with pickprogram (with the Find function in Script Editor) and delete that line.

  2. I am not sure about what version of the OS have these changes but if this is going to be distributed you may want to error check for OS version. My OS doesn’t support “file creator” (or at least it never works for me - 10.3.9). But “creator code” does.

Otherwise, not a bad piece of code for a newbie.

Have fun,
Jim

d’oh! the buttonResult thing was actually just left over from a previous attempt and i thought it might come in handy later (for whatever reason) so left it in. but, yeah, you’re right, it’s just clutter; the other thing, though, was sheer negligence…

the file creator/file type syntax i picked up from that line i posted earlier that i used to get the actual codes; i tried switching in “creator code” but it won’t compile. there was another thread about nearly the same thing – http://bbs.applescript.net/viewtopic.php?id=15959 – that used “creator type”. i tried that and voila! it works… see if this will work on your system; if not, i’ll make some adjustment for the OS issue.

thanks for the help guys!

here’s the final code:


property FileType : ""
property CreatorType : ""

on open theFiles
	tell application "Finder"
		activate
		
		set pickProgram to choose from list {"Quark 5", "Quark 6", "InDesign", "Illustrator AI", "Illustrator EPS", "Illustrator PDF", "Acrobat PDF", "Photoshop PSD", "Photoshop TIFF", "Photoshop JPEG", "Photoshop GIF", "Photoshop EPS", "Word DOC", "Word RTF", "Plain TXT"} with prompt ¬
			"What kind of file should this be?" OK button name "Go Man" cancel button name "Nevermind"
		
		if (pickProgram as string) = "Quark 5" then
			set FileType to "XDOC"
			set CreatorType to "XPR3"
			
		else if (pickProgram as string) = "Quark 6" then
			set FileType to "XPRJ"
			set CreatorType to "XPR3"
			
		else if (pickProgram as string) = "InDesign" then
			set FileType to "IDd4"
			set CreatorType to "InDn"
			
		else if (pickProgram as string) = "Illustrator AI" then
			set FileType to "PDF "
			set CreatorType to "ART5"
			
		else if (pickProgram as string) = "Illustrator EPS" then
			set FileType to "EPSF"
			set CreatorType to "ART5"
			
		else if (pickProgram as string) = "Illustrator PDF" then
			set FileType to "PDF "
			set CreatorType to "ART5"
			
		else if (pickProgram as string) = "Acrobat PDF" then
			set FileType to "PDF "
			set CreatorType to "CARO"
			
		else if (pickProgram as string) = "Photoshop PSD" then
			set FileType to "EPSF"
			set CreatorType to "8BIM"
			
		else if (pickProgram as string) = "Photoshop TIFF" then
			set FileType to "TIFF"
			set CreatorType to "8BIM"
			
		else if (pickProgram as string) = "Photoshop JPEG" then
			set FileType to "JPEG"
			set CreatorType to "8BIM"
			
		else if (pickProgram as string) = "Photoshop GIF" then
			set FileType to "GIFf"
			set CreatorType to "8BIM"
			
		else if (pickProgram as string) = "Photoshop EPS" then
			set FileType to "EPSF"
			set CreatorType to "8BIM"
			
		else if (pickProgram as string) = "Word DOC" then
			set FileType to "W8BN"
			set CreatorType to "MSWD"
			
		else if (pickProgram as string) = "Word RTF" then
			set FileType to "W8BN"
			set CreatorType to "MSWD"
			
		else if (pickProgram as string) = "Plain TXT" then
			set FileType to "ttxt"
			set CreatorType to "TEXT"
		end if
		
		repeat with eachFile in theFiles
			set the file type of eachFile to FileType
			set the creator type of eachFile to CreatorType
		end repeat
		
	end tell
end open

Hi Ray.

Nice script. You might want to add a condition that prevents the script from continuing if the user presses the Cancel/Nevermind button.

You could probably also condense the script slightly with something like this:

property app_list : {"Quark 5", "Quark 6", "InDesign", "Illustrator AI", "Illustrator EPS", "Illustrator PDF", "Acrobat PDF", "Photoshop PSD", "Photoshop TIFF", "Photoshop JPEG", "Photoshop GIF", "Photoshop EPS", "Word DOC", "Word RTF", "Plain TXT"}
property type_list : {{"XDOC", "XPR3"}, {"XPRJ", "XPR3"}, {"IDd4", "InDn"}, {"PDF ", "ART5"}, {"EPSF", "ART5"}, {"PDF ", "ART5"}, {"PDF ", "CARO"}, {"EPSF", "8BIM"}, {"TIFF", "8BIM"}, {"JPEG", "8BIM"}, {"GIFf", "8BIM"}, {"EPSF", "8BIM"}, {"W8BN", "MSWD"}, {"W8BN", "MSWD"}, {"ttxt", "TEXT"}}

to get_types from file_kind
	repeat with i from 1 to count app_list
		if file_kind is app_list's item i then return type_list's item i
	end repeat
end get_types

to open file_list
	tell (choose from list app_list with prompt "Choose the kind of files required:")
		if it is false then error number -128
		set new_types to my (get_types from item 1)
	end tell
	tell application "Finder" to repeat with curr_file in file_list
		set {curr_file's file type, curr_file's creator type} to new_types
	end repeat
end open

One final thought: For completeness, you may want to consider changing the name extension of the files, too. If you want help with this, just post a list of the required extensions here… :slight_smile:

SWEET!! that’s a MUCH more elegant solution! i was going to try to do this in the first place, but was too lazy! :stuck_out_tongue: and that “to” command is one i haven’t seen before… the file extension thing was actually my next step, so good timing! i’ll let you know when i pull it together.

thanks again!
ray.