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

mar627

macrumors newbie
Original poster
May 23, 2013
11
0
Hello,

I have a workflow that takes all the files from a directory and any within subdirectories, then moves them. The files are filtered, then moved. But, as you can see my filter picks up three files but only moves two. This must be because it can't move two files with the same name into the one destination (I assume). I want to stop/end the workflow if this happens, unfortunately renaming or adding a number to any duplicates is not an option due to their filename linkages within other applications.

I've added an AppleScript step now which prompts me if their are duplicates found:

Code:
on run {input, parameters}
    set nameList to {}
    repeat with i from 1 to count input
        try
            set thisItem to item i in input
            set thisItemsInfo to info for thisItem
            set thisItemsFileName to name in thisItemsInfo
            if thisItemsFileName is in nameList then
                set theAlertText to thisItemsFileName
                set theAlertMessage to "To stop overwriting files, the job was cancelled. This is because atleast two files with the same filename were found throughout the selected folder and it's subfolders."
                display alert theAlertText message theAlertMessage
            end if
            copy thisItemsFileName to the end of the nameList
        end try
    end repeat
end run

How can I end/stop/kill a running workflow from the AppleScript step? Ideally that would happen when the user hits "Okay" on the existing alert dialog.

I am testing as a .workflow file. But this will eventually become an application once ready.

Thanks!
 

Attachments

  • names.png
    names.png
    181 KB · Views: 313
To quit the workflow, just use an error number -128 statement. This is the "user canceled" error, but note that all errors are currently ignored within your try statement, so you would need to refactor and/or add an on error part. Another option would be to use an if...else statement to either copy the file or add it to a skipped list, which is displayed at the end of the script.
 
  • Like
Reactions: mar627
To quit the workflow, just use an error number -128 statement. This is the "user canceled" error, but note that all errors are currently ignored within your try statement, so you would need to refactor and/or add an on error part. Another option would be to use an if...else statement to either copy the file or add it to a skipped list, which is displayed at the end of the script.

Perfect. Was a little fiddly with the error part, may incorporate the is else statement if I keep running into files with the same filename. Thanks for you help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.