Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve list of selected files from active finder window using NSAppleScript
    primarykey
    data
    text
    <p>Does any one know how I could retrieve a list of selected files from the active finder window? I have no experience at all with AppleScript and your help will be appreciated!</p> <p>I tried using the following code from another answer on SO, but I could get it to return anything at all. No error, no results, just nothing. I understand that even if it did work, then it would just get me the first file, I need the complete selection of files..</p> <pre><code>NSAppleScript *script = [[NSAppleScript alloc] initWithSource: @"tell application \"Finder\"\n" "set selectedItems to selection\n" "if ((count of selectedItems) &gt; 0) then\n" "set selectedItem to (item 1 of selectedItems) as alias\n" "container window of selectedItem\n" "end if\n" "end tell\n"]; if (script == nil) { NSLog(@"failed to create script!"); } NSAppleEventDescriptor *result = [script executeAndReturnError:&amp;errorMessage]; if (result) { // POSIX path returns trailing /'s, so standardize the path NSString *path = [[result stringValue] stringByStandardizingPath]; } for (id key in errorMessage) { NSLog(@"key: %@, value: %@", key, [errorMessage objectForKey:key]); } </code></pre> <p><strong>Edit</strong></p> <p>I was printing out the error dictionary before executing the script, that is why there was no error. This is what I get when I select two files in a finder window:</p> <pre><code>2013-07-23 13:36:14.817 myAPP[12959:303] key: NSAppleScriptErrorMessage, value: Finder got an error: Can’t get container window of document file "myAPP-logo-white-n-black.png" of folder "untitled folder" of folder "Desktop" of folder "Shumais" of folder "Users" of startup disk. 2013-07-23 13:36:14.817 myAPP[12959:303] key: NSAppleScriptErrorRange, value: NSRange: {151, 16} 2013-07-23 13:36:14.817 myAPP[12959:303] key: NSAppleScriptErrorBriefMessage, value: Can’t get container window of document file "myAPP-logo-white-n-black.png" of folder "untitled folder" of folder "Desktop" of folder "Shumais" of folder "Users" of startup disk. 2013-07-23 13:36:14.818 myAPP[12959:303] key: NSAppleScriptErrorNumber, value: -1728 2013-07-23 13:36:14.818 myAPP[12959:303] key: NSAppleScriptErrorAppName, value: Finder </code></pre> <p>Thank You! Shumais</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload