I have a script which moves files around to different folders depending on their name. It is a folder action script. It all works fine, EXCEPT when the move involves a move to a folder on an external volume. The mv script cannot apparently see the volume folder, for some strange reason. It generates an error:
The volume “MacMiniOfficeData” exists. It is mounted and the file path is correct. Is there some limitation of the shell script mv command here? Is it unable to move stuff to an external volume? The script happily moves files to the folders on the startup volume.
The script is as follows:
on adding folder items to this_folder after receiving listfilec
--set listfilec to choose file with multiple selections allowed without invisibles
--display dialog listfilec as text
--set this_folder to "MacMiniOfficeHD:Users:macminia:Movies:EyeTV Encoded Store"
set this_folder to POSIX path of this_folder
set {TID, text item delimiters} to {text item delimiters, ":"}
repeat with parsen from 1 to count (listfilec)
set item parsen of listfilec to last text item of (item parsen of listfilec as text)
end repeat
set text item delimiters to TID
set listoffilesfolders to {"Basil", (POSIX path of (path to movies folder) & "EyeTV Encoded Store/testfolder"), "Pott", (POSIX path of (path to movies folder) & "EyeTV Encoded Store/testfolder2"), "Aliyas", POSIX path of "MacMiniOfficeData:AlexStuff"}
repeat with filec in listfilec
repeat with check from 1 to count (listoffilesfolders) by 2
if filec contains item check of listoffilesfolders then
my movefile(this_folder, item (check + 1) of listoffilesfolders, filec, filec)
end if
end repeat
end repeat
end adding folder items to
on movefile(thefolderfrom, thefolderto, moveitem, destfilename)
set sourceFilePath to quoted form of (thefolderfrom & "/" & moveitem)
set targetFilePath to quoted form of (thefolderto & "/" & destfilename)
do shell script "mv " & sourceFilePath & " " & targetFilePath -- to move file
end movefile
the coercion from a literal string path to a POSIX path doesn’t add /Volumes automatically,
just add file. If the path is valid, /Volumes will be added
.
, POSIX path of file "MacMiniOfficeData:AlexStuff"}
.
POSIX path of file "MacMiniOfficeData:AlexStuff" &
POSIX path of "MacMiniOfficeData:AlexStuff"
both return the same thing:
In experimenting, I tried setting “Ignore Permissions” on the volume “MacMiniOfficeData” and the script worked as is. I am confused though as the error message was about a no such file or directory (not a permission denied). Why would permissions make any difference? Is there any way of leaving the volume with permissions set AND having the script work?
I have a similar problem with my script. It moves the files if located on the internal HD, but if I apply the script on files on an external drive it stopps exactly at the move statement. (I need to move because normally the files are in subfolders I don’t want them to be in. I just want Artist Folder, Subfolder Album and the files in it.)
@kiwilegal: how can I set “Ignore Permissions”? Where do I have to do it?
tell application "Finder"
set theTIDs to AppleScript's text item delimiters --save original TIDs
set theArtistFolders to (choose folder with multiple selections allowed) as list
repeat with artistFold in theArtistFolders --iterate over all artists in container
set theArtist to item -2 of (my text_to_list(artistFold as string, ":"))
set theAlbumFolders to my get_folder_list(artistFold as string, {}, false, false)
repeat with albumFold in theAlbumFolders --iterate over all albums of artist
set theAlbum to item -2 of (my text_to_list(albumFold as string, ":"))
set theSongs to entire contents of folder albumFold
set theSongs_ref to (a reference to theSongs)
repeat with each in theSongs_ref --iterate over all files of the album Folder
if (class of each is not folder) then --process only valid files
repeat with counter from 1 to 50 --easiest way to find out Track number
if ((name of each) contains ("(Ch" & counter & " - Ch" & counter & ")")) then --true if track number found
set each_alias to each as alias
display dialog "Please set name for" & return & return & "Track " & counter & return & "Album " & theAlbum & return & "Artist " & theArtist default answer "" buttons {"Cancel", "OK"} default button 2
copy the result as list to {text_returned, button_pressed}
if text_returned is not "" then --only set new name for non empty values
set (name of each) to (theArtist & " () " & theAlbum & " () " & counter & " () " & text_returned & ".vob")
end if
move (each_alias) to albumFold
exit repeat --exit the Track finding loop an go to next song
end if
end repeat
end if
end repeat
repeat with each in theSongs_ref -- delete empty folders
try
if (class of each is folder) then delete each
end try
end repeat
end repeat
end repeat
set AppleScript's text item delimiters to theTIDs --restore original TIDs
end tell
to searchReplace(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end searchReplace
(* Parameter description
set the_folder to (path to desktop) as string
set file_types to {"osas", "TEXT"} --file types, set to {} and inc_folders to true to just return folders
set with_subfolders to true --list subfolders or not (recursion)
set inc_folders to false --include folders in the list of files to return
*)
to get_folder_list(the_folder, file_types, with_subfolders, inc_folders)
set the_files to {}
tell application "Finder" to set folder_list to every item of folder the_folder
repeat with new_file in folder_list
try
set temp_file_type to file type of new_file
on error
set temp_file_type to "fold"
end try
if file_types contains temp_file_type or file_types = {} then set the_files to the_files & {new_file as string}
if temp_file_type = "fold" then
if inc_folders = true and file_types = {} then set the_files to the_files & {new_file as string}
if with_subfolders = true then set the_files to the_files & my get_folder_list((new_file as string), file_types, with_subfolders, inc_folders)
end if
end repeat
return the_files
end get_folder_list
to text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (theList)
end text_to_list