Search code examples
applescriptosx-yosemite

Issues with "On Open" Applescript handler in Yosemite


In using Applescript in OSX 10.10 (Yosemite), it seems Apple has changed some of the default behavior.

on open dropped_files
   display dialog (count of dropped_files)
end open

This very basic Applescript highlights the problem. If I select a group of 6 files from the Finder, and drop/drop onto a compiled version of this script, I get the response "2" and then the response "4". It should be responding "6"... but it's almost as if Finder is parsing the files into smaller groups. If I do this again, I get a different combination of numbers, so it does not seem to be consistent.

This is not the desired behavior for my application, any ideas for a solution? I never saw this behavior with older versions of Applescript.


Solution

  • This bizarre effect is due to quarantined files. Quarantined files can be checked with the command:

    xattr -p com.apple.quarantine *
    

    Depending on the sort order of the quarantined/non-quarantined files, it will separately execute the "on open" handler for each group (be it quarantined or non-quarantined): e.g., 1 - quarantined, 4 - non-quarantined, 3 - quarantined. You'll notice there are two groups of quarantined files being submitted in this example, and that's because of how that particular list was sorted and submitted to the on open handler.

    This behavior is rather surprising, and I've submitted it as a bug report to Apple. The quarantine attribute can be removed with this command:

    sudo xattr -dr com.apple.quarantine *
    

    to show the correct number of files. Also, see the Applescript trick above by regulus6633 for a clever workaround.