Skip to main content
added 369 characters in body
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

The selection in Finder returns a list, so here is an example of how I'd handle things:

Example AppleScript code:

tell application "Finder"
    set theSelection to selection
    if theSelection is {} then
        return
    else if (theSelection count) is equal to 1 then
        set thePathFilename to the quoted form of POSIX path of (theSelection as string)
    else
        set thePathFilename to {}
        repeat with i from 1 to (theSelection count)
            copy (quoted form of POSIX path of (item i of theSelection as string)) & space to end of thePathFilename
        end repeat
        set thePathFilename to thePathFilename as string
    end if
end tell
  • If there is no selection when the script runs, it stops processing.

  • If only one item is in the selection, the thePathFilename contains one quoted POSIX Path Filename of the selected item, as a string.

  • If more then one item is in the selection, the thePathFilename contains the quoted POSIX Path Filename of each of the selected items, as a string, with a space after each.


Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.

The selection in Finder returns a list, so here is an example of how I'd handle things:

Example AppleScript code:

tell application "Finder"
    set theSelection to selection
    if theSelection is {} then
        return
    else if (theSelection count) is equal to 1 then
        set thePathFilename to the quoted form of POSIX path of (theSelection as string)
    else
        set thePathFilename to {}
        repeat with i from 1 to (theSelection count)
            copy (quoted form of POSIX path of (item i of theSelection as string)) & space to end of thePathFilename
        end repeat
        set thePathFilename to thePathFilename as string
    end if
end tell

Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.

The selection in Finder returns a list, so here is an example of how I'd handle things:

Example AppleScript code:

tell application "Finder"
    set theSelection to selection
    if theSelection is {} then
        return
    else if (theSelection count) is equal to 1 then
        set thePathFilename to the quoted form of POSIX path of (theSelection as string)
    else
        set thePathFilename to {}
        repeat with i from 1 to (theSelection count)
            copy (quoted form of POSIX path of (item i of theSelection as string)) & space to end of thePathFilename
        end repeat
        set thePathFilename to thePathFilename as string
    end if
end tell
  • If there is no selection when the script runs, it stops processing.

  • If only one item is in the selection, the thePathFilename contains one quoted POSIX Path Filename of the selected item, as a string.

  • If more then one item is in the selection, the thePathFilename contains the quoted POSIX Path Filename of each of the selected items, as a string, with a space after each.


Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.

Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

The selection in Finder returns a list, so here is an example of how I'd handle things:

Example AppleScript code:

tell application "Finder"
    set theSelection to selection
    if theSelection is {} then
        return
    else if (theSelection count) is equal to 1 then
        set thePathFilename to the quoted form of POSIX path of (theSelection as string)
    else
        set thePathFilename to {}
        repeat with i from 1 to (theSelection count)
            copy (quoted form of POSIX path of (item i of theSelection as string)) & space to end of thePathFilename
        end repeat
        set thePathFilename to thePathFilename as string
    end if
end tell

Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.