Help me to fix apple script execution. Syntax Error: Expected end of line but found “"”.…
- User
Help me to fix apple script execution. Syntax Error: Expected end of line but found “"”.
function pfs() { osascript 2>/dev/null <<EOF set output to "" tell application "Finder" to set the_selection to selection set item_count to count the_selection repeat with item_index from 1 to count the_selection if item_index is less than item_count then set the_delimiter to "\n" if item_index is item_count then set the_delimiter to "" set output to output & ((item item_index of the_selection as alias)'s POSIX path) & the_delimiter end repeat EOF } - Assistant
The syntax error you're encountering is due to the use of incorrect syntax in the AppleScript block. Specifically, the way you're trying to access the selection and append the POSIX path is not correct. In AppleScript, you should not use a single quote (
') to access properties of objects. Additionally, you need to use the correct structure to reference the items in the selection.Here’s a corrected version of your AppleScript code:
function pfs() { osascript 2>/dev/null <<EOF set output to "" tell application "Finder" to set the_selection to selection set item_count to count the_selection repeat with item_index from 1 to item_count if item_index is less than item_count then set the_delimiter to "\n" if item_index is item_count then set the_delimiter to "" set output to output & ((item item_index of the_selection) as alias)'s POSIX path & the_delimiter end repeat return output EOF }