Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

super_kev

macrumors 6502
Original poster
Jan 12, 2005
356
2
USofA
Hi all,
I'm getting the following error when I run this script:

Can't make {alias "HD:Blah:A:MusicFile1.mp3", alias "HD:Blah:A:MusicFile2.mp3"} into type string

I have a two folders with files in them, and I want the script to fetch a list of files in Folder A, then move them to Folder B which already has other files in it. Later on (haven't built the rest of the script yet), I am going to move the files I originally moved to Folder B, and move them back to Folder A.

Code:
tell application "Finder"
	set Afolder to "HD:Blah:A:" as alias
	set a_list to every file in Afolder as alias list
	repeat with i from 1 to number of items in a_list
		set a_file to (item i of a_list)
		move a_file to "HD:Blah:B"
	end repeat
end tell

I've ordered an Applescript book, but it's not here yet, and I haven't found any decent tutorials regarding Applescript lists while searching the 'net. I know the problem is with the third line (set a_list to every file...) but I don't know what I am doing wrong.

Any help would be appreciated, thanks.
 
The problem is actually with the line move a_file to "HD:Blah:B". You're trying to perform the move command on an alias, when you should be performing it on a reference (also known as an object specifier).

An alias is just a string containing an HFS path, whereas a reference describes an actual object within the Finder's AppleScript object hierarchy.

The fix is simple:

Code:
tell application "Finder"
	set Afolder to "HD:Blah:A:" as alias
	set a_list to every file in Afolder
	repeat with i from 1 to number of items in a_list
		set a_file to (item i of a_list)
		move a_file to "HD:Blah:B"
	end repeat
end tell

By removing the "as alias list" bit, a_list becomes a list of references rather than a list of aliases.
 
By the way, I can see why you made the mistake, because you are able to refer to the source and destination folder objects by their aliases. I'm not sure how this is done (coercion, I think), nor am I sure why it doesn't work when you're specifying the main reference for the move command.
 
you need to set the individual items to strings before manipulating them, as in the following script.
Code:
tell application "Finder"
	set theList to every file of folder (path to desktop folder as string)
	set i to 1
	repeat the count of theList times
		set theItem to item i of theList as string
		--then manipulate it.
		set i to i + 1
	end repeat
end tell
 
Thanks for the help, guys. However, I'm still having problems. :(

The fix is simple:

Code:
tell application "Finder"
	set Afolder to "HD:Blah:A:" as alias
	set a_list to every file in Afolder
	repeat with i from 1 to number of items in a_list
		set a_file to (item i of a_list)
		move a_file to "HD:Blah:B"
	end repeat
end tell

By removing the "as alias list" bit, a_list becomes a list of references rather than a list of aliases.

Upon deletion of "as alias list", I get:

Can't make {<<class docf>> "MusicFile1.mp3" of <<class cfol>> "A" of <<class cfol>> "Blah" of <<class cdis>> "HD" of application "Finder", <<class docf>> "MusicFile2.mp3" of <<class cfol>> "A" of <<class cfol>> "Blah" of <<class cdis>> "HD" of application "Finder"

So, I'm not sure what was going on there...

***

If I change "set a_list to every file of Afolder as alias" to "set a_list to every file of folder Afolder as string", and put "display dialog a_list" after it (to see what a_list is putting out before going to the next step) I get "HD:Blah:A:MusicFile1.mp3HD:Blah:B:MusicFile2.mp3", and when I click ok on the dialog to continue the script, an error comes up "Can't get "F"". I am not sure what "F" is, as I don't call on any "F". I also don't know how to separate the two files so they can be read and moved.

you need to set the individual items to strings before manipulating them, as in the following script.

Using the following code, I get the same message as above (can't get "F").
Code:
tell application "Finder"
	set Afolder to "HD:Blah:B:" as alias
	set a_list to every file of folder Afolder as string
	display dialog a_list [i]--check output of a_list[/i]
	set i to 1
	repeat the count of a_list times
		set a_file to (item i of a_list) as string
		move a_file to "HD:Blah:B:"
		set i to i + 1
	end repeat
end tell

:confused:
 
Tiger as well. I just now copied and pasted the first script I posted (with your changes) in a new script window and saved, and it works. Weird. :confused: Thanks. :)
 
Using the following code, I get the same message as above (can't get "F").
Code:
tell application "Finder"
	set Afolder to "HD:Blah:B:" as alias
	set a_list to every file of folder Afolder [B]as string[/B]
	display dialog a_list [i]--check output of a_list[/i]
	set i to 1
	repeat the count of a_list times
		set a_file to (item i of a_list) as string
		move a_file to "HD:Blah:B:"
		set i to i + 1
	end repeat
end tell

The first as string (in bold) needs removing, it's turning the whole list into a string, so each item in the list is a single character. This gives the script which should work:
Code:
tell application "Finder"
	set Afolder to "HD:Blah:B:" as alias
	set a_list to every file of folder Afolder
	display dialog a_list [i]--check output of a_list[/i]
	set i to 1
	repeat the count of a_list times
		set a_file to (item i of a_list) as string
		move a_file to "HD:Blah:B:"
		set i to i + 1
	end repeat
end tell
 
PS I hit that problem too, you will find it easier to make the script line by line and see what result Applescript kicks back to the screen, or by using the event log (tab to toggle this at the bottom of the script editor window ;).
 
Ok, I found my problem, it was with "display dialog a_list". With that code out of both scripts, they work. I wouldn't have thought that display dialog would affect the rest of the script like it did. I've posted the two working versions below:

Code:
tell application "Finder"
	set Afolder to ((container of (path to me) as string) & "A") as alias
	set a_list to every file in Afolder
	repeat with i from 1 to number of items in a_list
		set a_file to (item i of a_list)
		move a_file to ((container of (path to me) as string) & "B")
	end repeat
end tell

**

Code:
tell application "Finder"
	set Afolder to ((container of (path to me) as string) & "A") as alias
	set a_list to every file of folder Afolder
	set i to 1
	repeat the count of a_list times
		set a_file to (item i of a_list) as string
		move a_file to ((container of (path to me) as string) & "B")
		set i to i + 1
	end repeat
end tell

Thanks guys.
 
I've run into another problem, and after searching for the past hour or so, I haven't found a solution that would work. :eek: The reason for getting the list of files in Folder A is so that I could move them in to Folder B, and back into Folder A without moving other files that are already in Folder B.

I've modified the working code above, but I think my problem is where I set b_list to a_list. Running the Event Log shows that the script is trying to move the files from Folder A instead of Folder B, so how can I get rid of the path (convert "HD:Blah:A:File1" to "File1") so I can use it in b_list and move to the correct directory ("HD:Blah:B")?

Code:
tell application "Finder"
	set Afolder to "HD:Blah:A" as alias
	set Bfolder to "HD:Blah:B" as alias
	
	set a_list to every file in Afolder
	repeat with i from 1 to number of items in a_list
		set a_file to (item i of a_list)
		move a_file to Bfolder
	end repeat
	
	delay 3
	
	set b_list to a_list [i]--get file list that was given in a_list[/i]
	repeat with j from 1 to number of items in b_list
		set b_file to (item j of b_list)
		move b_file to Afolder
	end repeat
end tell
 
I finally got it. I set a "list_a" to files in folder A, then set a list_b to files in folder B (before moving files of A into B). Then, after I moved the files of A into B, I got a list of files in folder B again (set it to "list_c", for example), then compared list_b (before move) to list_c. (if c_file is in b_filelist than do nothing, else move...) The files that were in list_c but not in list_b, I moved back into folder A. I compared lists with the help of this thread. :)
 
similar get list problem

I am attempting to run an old Claris Emailer applescript, which ran on OS 9.2.2 to a Mail application running on OS 10.3.9. I've encountered several problems. When I try to change the first line from "Claris Emailer" to "Mail" I get the error message"Expected end of line but found number". The error refers to the number 2 in the second line (set inboxFolder to folder 2 -- "In box").

Also, the applescript shows some event and class errors:

set subFolder to («event FrBlfbss» thesubject without «class mpts» given «class ford»:2)

set imgFolderAlias to «class cfol» "WATERMARKED_IMAGES" of «class cdis» "untitled"

Any help would be most welcome. Here is the script...

**********************

tell application "Claris Emailer"
set inboxFolder to folder 2 -- "In box"
repeat until (count of messages in inboxFolder) is 0
try
-- Get the message
set msg to (message 1 of inboxFolder)

-- Grab the subject, sender's name and email, and body for later use in the script
set thesubject to (subject of msg)
set thesender to (sender of msg)
set senderName to (display name of thesender)
set senderEmail to (address of thesender)
set theBody to (content of msg)

-- The subject should always be 6 characters long (the image id)
-- If not, its probably not an image request, so just ignore it
if length of thesubject is 6 then

-- Store information about this request in our FileMaker database for future reference
tell application "FileMaker Pro"
set recordRef to create new record at database "EmailDatabase2"
set data (cell "Name" of recordRef) to senderName
set data (cell "Email" of recordRef) to senderEmail
set data (cell "ImgRqst" of recordRef) to thesubject
set data (cell "Message" of recordRef) to theBody
end tell

-- Attempt to locate the image id found in the subject and attach that image in the reply
-- If we can't find it, send a reply stating so
try
tell application "Finder"

-- Parse the image id so we can determine which folder the image should be in
set subFolder to («event FrBlfbss» thesubject without «class mpts» given «class ford»:2)

-- Set the path to the Images folder.
-- THIS MUST BE SET IN THE CORRECT FORMAT OR THE SCRIPT WILL FAIL!!
set imgFolderAlias to «class cfol» "WATERMARKED_IMAGES" of «class cdis» "untitled"
set imgFolderPath to imgFolderAlias as string
set imgPath to (imgFolderPath & subFolder & ":" & thesubject & ".JPG")

-- This is where we actually determine if the image exists
-- If not, the 'on error' code will execute next
set imgAlias to imgPath as alias
set fileList to {imgAlias as string}
end tell

-- Create a new message, assemble it, and hold it in the 'Outbox' until the next connection
set newsubject to "Image: " & thesubject
set msgReply to "
************

You may obtain a non-watermarked version by calling 701-947-5932 (888-966-5932 in USA) or, by emailing painet@stellarnet.com , with the subject of the email being COMP REQUESTED and the body of the email containing the image IDs requested. Explain why you would like the mon-watermarked versions.

As a service we have provided you this copyrighted image for COMPING/VIEWING purposes ONLY. The image may be saved and used in layouts or other printed forms, including multimedia use, for review and evaluation only.

COMPING/VIEWING is defined as using the image, in your layout or artwork, for viewing by ten or fewer people.

For viewing of this image by more than 10 people, licensing rights must be purchased.

To purchase licensing rights to this image, or a larger version of this image, search for the 6-character Image Name at:

www.painetworks.com

When the image is found, click on the Shopping Cart link, to the right of the thumbnail image, to access the order page.

Note: If the original Image Name has been changed, open the image in Photoshop. Go to File:File Info:Section:Keywords. The Image Name will be the top keyword.

You may purchase licensing rights to images by calling 1-888-966-5932 (701-947-5932), by emailing us at painet@stellarnet.com, or online at http://www.painetworks.com/cgi-bin/purchasemulti.cgi

Licensing rights and fees can be seen at http://www.painetworks.com/cgi-bin/purchasemulti.cgi

************
Note that not all images are full screen size. Approximately one-half of one percent are the same 300 pixel version seen online. However, you can order up to 55Mb (8 x 12 inches @ 300 dpi) versions of these images online at http://www.painetworks.com/cgi-bin/purchasemulti.cgi, or by calling 888-966-5932 (701-947-5932), or by emailing painet@stellarnet.com..
************

Painet Inc.
PO Box 431
New Rockford, ND 58356
tel: (701) 947-5932
tel: (888) 966-5932
fax: (701) 947-5933

************

Copyrights and all rights are reserved by the photographer represented. No part of this digital image may be used, reproduced or transmitted in any form or by any means, electronic, optical, mechanical, or otherwise, including without limitation, use on the internet, without the express permission of the photographer. Photographer's permission is expressly granted upon receipt and payment of a Painet Inc. invoice listing the image ID and the agreed upon license fee for image use rights.

For more detailed copyright information, see the US Copyright Office pages

http://lcweb.loc.gov/copyright/
"
make new outgoing message with properties {subject:newsubject ¬
, recipient:{address:thesender, recipient type:to recipient} ¬
, file:fileList, scheduled:true, compress enclosures:false, enclosure encoding:base64 ¬
, content:msgReply}

-- The image was found, make a note of it
tell application "FileMaker Pro"
set data (cell "WasFound" of recordRef) to "Found"
end tell

on error
tell application "Claris Emailer"

-- We couldn't find the file, send a reply stating so
-- Create a new message, assemble it, and hold it in the 'Outbox' until the next connection
set newsubject to "Image Not Found: " & thesubject
set msgReply to "The image you requested could not be found on our system!"
make new outgoing message with properties {subject:newsubject ¬
, recipient:{address:thesender, recipient type:to recipient} ¬
, content:msgReply}

-- The image was NOT found, make a note of it
-- By default, the Found field is NOT checked, so we'll just leave it that way

end tell
end try
end if

-- We're done with this email, delete it and start processing the next email
delete msg

-- The delay here is to allow the processor to do its work in the other applications as well rather than letting Claris be a hog

on error

-- An error occured...
-- There are a few reasons that can cause this...
-- 1) The appropriate FileMaker database was not open or frontmost when the script tried to enter data
-- 2) There was an unexpected error with the email itself
-- 3) Claris did somthing unexpected
display dialog ¬
¬
"An error occured while processing an email. ¬
Please edit this script and read the comments at the bottom for hints as to why this happened!" buttons {"End Script", "OK"} ¬
default button "OK" giving up after 2
if button returned is "End Script" then
return
end if
end try
end repeat

-- Were all done with this batch, if were not already connected and doing something, connect, send the replies, and check for new mail
if not connection in progress then
connect to "Image Request" with sending and checking
end if

end tell
 
Basically, your problem is Mail and Emailer have entirely different dictionaries, so Script Editor is getting very confused. Just changing the "tell application" line isn't enough. You need to do some research, figure out the vocabulary and then rewrite the code.

This code looks complicated enough that you might be better off trying to start from scratch doing the basics with Mail, then once you've got that down, move over the boilerplate.

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.