Benches macOS

7

How to move files instead of deleting in …

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

Hello!

I found this awesome code by SGIII in an older thread and it works great to delete RAW files that do not match JPG in another folder. However for safety it would be perfect if the script could:

  • Create a new subfolder "RAW files to delete" in the RAW folder
  • Move those RAW files that do not have a equivalent JPG file to that folder

I tried to google and change the script, but since I'm a total newbie I couldn't do it.

That would make it more safe, since I otherwise could accidentally delete some files that are still needed.

Here is the script:

tell application "Finder"

set fr to choose folder with prompt "Choose subfolder with RAW files"

set fj to choose folder with prompt "Choose subfolder with corresponding JPEG files"

set {rFiles, jFiles} to {fr's files as alias list, fj's files as alias list}

set {rNames, jNames} to {my stripExt(rFiles), my stripExt(jFiles)}

repeat with i from 1 to count rFiles

if rNames's item i is not in jNames then delete rFiles's item i

end repeat

end tell

to stripExt(fileList) -- removes extension so names can be compared

set nn to {}

tell application "Finder"

repeat with f in fileList

set nn's end to ¬

(f's name as text)'s text 1 thru -(((f's name extension as text)'s length) + 2)

end repeat

end tell

return nn

end stripExt

I would really appreciate if somebody could help me out on with this :)

7 replies

Sign in or join Beachball Help to reply.

  1. 0

    Niel

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Replace the first repeat segment with:

    set raw_folder to (make folder at rFiles with properties {name:"RAW files to delete"})

    repeat with i from 1 to count rFiles

    if rNames's item i is not in jNames then move rFiles's item i to raw_folder

    end repeat

    (167128)

  2. 0

    Niel

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Replace the first repeat segment with:

    set raw_folder to (make folder at rFiles with properties {name:"RAW files to delete"})

    repeat with i from 1 to count rFiles

    if rNames's item i is not in jNames then move rFiles's item i to raw_folder

    end repeat

    (167128)

  3. 0

    Rosenvald

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hi, Niel!

    Thanks a lot for your answer!

    I tried it through automator and I got an error message:

    "Finder got an error: You don't have permission to create folder here."

    Do you know what might cause this?

    All the best

    Valdur

  4. 0

    Luis Sequeira1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    1) Where is "here"?

    2) You may need to give Automator and your workflow permission to control your computer. This is part of the new security restrictions in Mojave.

    System Preferences->Security & Privacy->Privacy, click on Accessibility; click the padlock to authenticate, then add the desired items to the list.

  5. 0

    Rosenvald

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    1) It is on my Macintosh HD downloads folder. I also tried on Documents folder and on an external HDD. Still the same error.

    2) I added Automator to the apps that have control, but I still get the same error, no permission to create the folder.

    Any more ideas?

    Huge thanks in advance!

    Valdur

  6. 0

    Luis Sequeira1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    There is bug in the code that Niel proposed.

    Instead of

    set raw_folder to (make folder at rFiles with properties {name:"RAW files to delete"})

    repeat with i from 1 to count rFiles

    if rNames's item i is not in jNames then move rFiles's item i to raw_folder

    end repeat

    it should be:

    set raw_folder to (make folder at fr with properties {name:"RAW files to delete"})

    repeat with i from 1 to count rFiles

    if rNames's item i is not in jNames then move rFiles's item i to raw_folder

    end repeat

    Note that in the first line where it says "rFiles" it should say "fr" - the latter is a folder, and the former is a collection of the files in that folder.

  7. 0

    Rosenvald

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Awesome, thank you so much, it seems to be working great!!!

    Valdur