Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript - Error 1700 Can't make ~ into type location specifier

The following script that someone on another thread so kindly created for me about a year ago used to work perfectly! Now it's not working and I can't figure out why and would love feedback. I can tell you the only change from the time it was created and running perfectly to now is that I upgraded to Mavericks OS 10.9.5.


A little background info on the purpose of the script if it helps. I use a .txt file with a select listing of part numbers (usually 100-500) to compare against a master folder of images of all parts (approx. 15,500). The script finds a match and places the image in a new folder. I use this for customer image requests rather than doing it manually. I will say that if in the process of figuring out the problem with the script someone can tell me how to copy rather than move the files that would be awesome! From what I've read, System Events doesn't do copy. I have tried using Finder but it just runs and then stops responding.


Using the script below, what used to work is now giving me the following error result message:


Result: error "System Events got an error: Can’t make \"/Users/myname/Desktop/Customer Img Req\" into type location specifier." number -1700 from "/Users/myname/Desktop/Customer Img Req" to location specifier


Thanks!


(I've substituted 'myname' for my actual below, otherwise this is exactly what the working script looked like before. Also, I realize the person who wrote the script misspelled 'imagePolderPath' but again - it used to work, misspelling and all.)

set imagePolderPath to "/Users/myname/Desktop/WEB IMAGE LIBRARY Incomplete"

set destinationFolderPath to "/Users/myname/Desktop/Customer Img Req"

-- choose the text file with the list of names

set listFile to POSIX path of (choose file)

-- the following assumes the list file is a text file with one image name per line

set dataList to paragraphs of (read listFile as «class utf8»)


tell application "System Events"

repeat with thisFileName in dataList

-- I've used 'begins with' since I don't know whether you'll get these file names with or without extensions. This could in aberrant cases result in unwanted files being included.

move (files of folder imagePolderPath whose name begins with thisFileName) to destinationFolderPath

end repeat

end tell

MacBook Pro, OS X Mavericks (10.9.5)

Posted on Dec 18, 2014 9:36 PM

Reply
11 replies

Dec 19, 2014 3:22 AM in response to DaughterJudas

Hello


You may try something like the following statement.


tell application "System Events" repeat with thisFileName in dataList move (files of folder imagePolderPath whose name begins with thisFileName) to end of files of folder destinationFolderPath end repeat end tell



Only tested under OS X 10.6.8. Not sure it works well under 10.9.


Good luck,

H



PS. Here's another AppleScript script using shell script, which is far faster and also lets you duplicate files instead of moving them.



set src to (path to desktop)'s POSIX path & "WEB IMAGE LIBRARY Incomplete" set dst to (path to desktop)'s POSIX path & "Customer Img Req" set lst to (choose file)'s POSIX path do shell script "/bin/bash -s <<'EOF' - " & src's quoted form & " " & dst's quoted form & " " & lst's quoted form & " SRC=\"$1\" DST=\"$2\" LIST=\"$3\" while read n do [[ -z $n ]] && continue # skip empty line cp -pPR \"$SRC/$n\"* \"$DST\" done < <(perl -CSDA -w -MUnicode::Normalize -lpe '$_ = NFD($_);' \"$LIST\") # [1] # [1] It seems NFD normalisation is not necessary for cp(1) to work properly without glob (under OS X 10.6.8). # However, if filename glob in shell is invoked, NFD normalisation is required. EOF"



* Note that, given abc in name list, this script will copy files matching abc*, which will include abc.jpg, abc.png, abcdef.jpg etc., as your original script does.

Dec 19, 2014 7:25 AM in response to Hiroto

@Hiroto - thank you for your suggestion. I tried modifying the script with your first statement. This is how I entered it:


-- choose the text file with the list of names


set listFile to POSIX path of (choose file)


-- the following assumes the list file is a text file with one image name per line


set dataList to paragraphs of (read listFile as «class utf8»)



tell application "System Events"

set imagePolderPath to "/Users/myname/Desktop/WEB IMAGE LIBRARY Incomplete"

set destinationFolderPath to "/Users/myname/Desktop/Customer Img Req"

repeat with thisFileName in dataList

-- I've used 'begins with' since I don't know whether you'll get these file names with or without extensions. This could in aberrant cases result in unwanted files being included.

move (files of folder imagePolderPath whose name begins with thisFileName) to end of files of folder destinationFolderPath

end repeat

end tell


Result: error "System Events got an error: AppleEvent handler failed." number -10000



As for the shell script, I'll admit I'm completely illiterate to that, so I wasn't sure how to enter this part to specify the file path:


set src to (path to desktop)'s POSIX path & "WEB IMAGE LIBRARY Incomplete"

set dst to (path to desktop)'s POSIX path & "Customer Img Req"

set lst to (choose file)'s POSIX path

Dec 19, 2014 7:39 AM in response to DaughterJudas

Well the error message you are getting is definitely telling you there is a problem with the destination folder.


How id you upgrade to Mavericks? Did you restore the system from backups or did you upgrade in place? When you upgraded to Mavericks did you need to create the folder in your Desktop? Any chances permissions got changed on the destination folder? That would cause the error also.


You could try this


with the editor open with this script drag the destination folder from the Finder into the script. When you let go the path will be copied into the script. Replace the path in the line:


setdestinationFolderPath to "/Users/myname/Desktop/Customer Img Req"

with the dragged in path.

Dec 19, 2014 8:46 AM in response to DaughterJudas

Hello


You may use those lines as they are :


set src to (path to desktop)'s POSIX path & "WEB IMAGE LIBRARY Incomplete" set dst to (path to desktop)'s POSIX path & "Customer Img Req" set lst to (choose file)'s POSIX path


because they are valid AppleScript statements.


Or if you prefer, you may set them like the following as well :


set src to "/Users/myname/Desktop/WEB IMAGE LIBRARY Incomplete" set dst to "/Users/myname/Desktop/Customer Img Req" set lst to (choose file)'s POSIX path




Good luck,

H

Dec 19, 2014 9:26 AM in response to Hiroto

@ Hiroto - I tried both version of shell script and the results for both were:


error "cp: /Users/myname/Desktop/WEB IMAGE LIBRARY Incomplete/baby\\rcowboy\\rwindow*: No such file or directory" number 1


I verified that the folders, lists, files and file names are all on my local hard drive desktop.


(FYI - baby, cowboy, and window are test file names - but not sure why it threw a letter 'r' in front of the 2nd and 3rd file name)

Dec 19, 2014 9:36 AM in response to Frank Caggiano

@Frank - If I'm not mistaken, there was no backup needed, just a simple download Mavericks from Apple and let it restart computer. The folders were there on my desktop prior to upgrade, so I didn't create a new one after. I checked the permissions and have read & write access.


I tried the drag/drop method from Finder to the Editor and when it asked if I wanted to copy contents I selected "Alias" instead to get path.


Result: error "System Events got an error: AppleEvent handler failed." number -10000

Dec 19, 2014 9:55 AM in response to DaughterJudas

Hello


\r is U+000D CR. It appears you're using CR as line ending in file name list. The script expects LF as line ending.


You may -


a) change line ending from CR to LF in your name list; or


b) use the following script for name list using CR line ending:



set src to (path to desktop)'s POSIX path & "WEB IMAGE LIBRARY Incomplete" set dst to (path to desktop)'s POSIX path & "Customer Img Req" set lst to (choose file)'s POSIX path -- # name list using CR line ending do shell script "/bin/bash -s <<'EOF' - " & src's quoted form & " " & dst's quoted form & " " & lst's quoted form & " SRC=\"$1\" DST=\"$2\" LIST=\"$3\" while read n do [[ -z $n ]] && continue # skip empty line cp -pPR \"$SRC/$n\"* \"$DST\" done < <(perl -CSDA -w -MUnicode::Normalize -lp015e '$_ = NFD($_);' \"$LIST\") # [1] # # [1] It seems NFD normalisation is not necessary for cp(1) to work properly without glob (under OS X 10.6.8). # However, if filename glob in shell is invoked, NFD normalisation is required. # EOF"



Hope this may help,

H


PS.


CR = CARRIAGE RETURN (U+000D)

LF = LINE FEED (U+000A)



EDIT: added PS.

Dec 19, 2014 9:54 AM in response to DaughterJudas

You might be dealing with multiple problems, there appears to be a bug in System Events that make the move command no longer behave as it once did. And I'm still not sure that your folders are setup correctly but…


Here is a version rewritten to use Finder rather then System Events. It works on my system once I created the two folders in my Desktop and create a text file with a filename to match. if you select it all, control click you can choose Make new Applescript from the contextual menu (either under Services or else at the top level)

(*

set imagePolderPath to "/Users/frank/Desktop/WEB IMAGE LIBRARY Incomplete" as POSIX file

set destinationFolderPath to "/Users/frank/Desktop/Customer Img Req" as POSIX file

*)


(* would be better to do it this way. *)


set imagePolderPath to (path to desktop as text) & "WEB IMAGE LIBRARY Incomplete"

set destinationFolderPath to (path to desktop as text) & "Customer Img Req"



-- choose the text file with the list of names

set listFile to POSIX path of (choose file)

-- the following assumes the list file is a text file with one image name per line

set dataList to paragraphs of (read listFile as «class utf8»)


tell application "Finder"

repeat with thisFileName in dataList


-- I've used 'begins with' since I don't know whether you'll get these file names with or without extensions. This could in aberrant cases result in unwanted files being included.


move (items of folderimagePolderPath whose name begins with thisFileName) todestinationFolderPath

end repeat

end tell

I modified the way the path to the Desktop is specified, doing it this way will guarantee the script will run no matter the name of the user running it


regards

Dec 19, 2014 9:58 AM in response to DaughterJudas

DaughterJudas wrote:



Result: error "System Events got an error: AppleEvent handler failed." number -10000

Yes that error is caused by the bug in Systems Events that I mentioned in my previous post.


You'll notice that the error changed from when you first ran the script to after you dragged in the file path. In the fist case the error was caused by the path on the disk being different then what is in the script. Once you fixed that by dragging in the path and having the correct path in the script you encountered the System Events bug.


As my last script relies on the folder names you supplied in your original script it will most likely error also on your system. If it does you will need to correct the folder names


regards

AppleScript - Error 1700 Can't make ~ into type location specifier

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.