0

mac os x で filemanager Path Finder を使用して、選択したファイル/フォルダーをpy-appscriptを使用して python で取得したい。py-appscript は、Python からスクリプト可能な Mac OS X アプリケーションを制御できる高レベルのイベント ブリッジです。

Applescriptでは、次のようになります

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

Pythonでは、代わりに次のようなものになります

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

では、selection_list の参照を python-strings に変換するにはどうすればよいですか?

4

2 に答える 2

0

python-applescript を試してみませんか。python を介して applescript のスクリプトを実行できます。ここで入手してください:http://pypi.python.org/pypi/python-applescript

于 2010-11-09T14:22:17.047 に答える
0

私は Pathfinder に精通していませんが、独自のファイル URL タイプ (または POSIX パスである可能性があります) がある場合、パス内のファイル階層のレベルを区切る何らかの区切り文字があると思われます。一方と他方の間で変換するには、を使用する必要がありますApplescript's text item delimiters。これらの線に沿った何かが機能するはずです

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.

塩を加えて味を調えます。ただし、PathFinder URL の例を提供していただければ、より適切な回答を提供できます。

于 2010-11-08T18:18:55.323 に答える