How can i access the file-selection in Path Finder via py-appscript?
Question: Using the filemanager Path Finder on mac os x, i wanna retrieve the selected
files/folders with python by using [py-
appscript](http://appscript.sourceforge.net). py-appscript is a high-level
event bridge that allows you to control scriptable Mac OS X applications from
Python.

In applescript it would be something like

    
    
    tell application "Path Finder"
     set selection_list to selection -- list of fsItems (fsFiles and fsFolders)
     set _path to posix path of first item of selection_list
     do shell script "python " & quoted form of _path
    end tell
    

In python it would instead something like

    
    
    from appscript import *
    selectection_list = app('Path Finder').selection.get()   # returns reference, not string
    

So, how can i convert the references in selection_list to python-strings?


Answer: I'm not familiar with Pathfinder, but if it has its own file URL type (or
maybe it's a POSIX path?), then there is presumably a delimiter of some kind
that separates the levels of file hierarchy in the path. To convert between
one and the other, you need to work with `Applescript's text item delimiters`.
Something along these lines should work

    
    
    set thePathFinderPath to "/pathfinder/path/to/finder"
    
    set pathFinderPathDelimiter to "/" -- whatever it may be here
    set finderPathDelimiter to ":"
    
    set AppleScript's text item delimiters to {pathFinderPathDelimiter}
    set thePathComponents to (get every text item in thePathFinderPath) as list
    set AppleScript's text item delimiters to {finderPathDelimiter}
    set theFinderPath to thePathComponents as text
    set AppleScript's text item delimiters to "" -- very important you clear the TIDs.
    

Add salt to taste. But, if you can provide an example of the PathFinder URL,
then I can provide a better answer.

