![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2007
Posts: 13
Rep Power: 0
![]() |
File path in Mac OS X
Hey all,
I'm pretty new Python, but I'm been reading over it and writing some cool scripts. I've developed a script and I need a little help with something that seems to be really easy but, for the life of me, I cannot figure out how to do it. Say I have a finder window open and have a directory selected. If I were to make my pyton script an app and were to select the directory and then run the script/app, how do I get the entire path of the directory? If anyone could help me out it would be greatly appreciated. Thanks! :banana: |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Are you asking how to determine the path of the directory currently selected in the Finder, or just how to get the path of a particular directory to use in your script?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Feb 2007
Posts: 13
Rep Power: 0
![]() |
Thanks for replying back. I'm asking how to determine the path of the directory currenttly selected in the finder.
|
|
|
|
|
|
#4 |
|
Expert Programmer
|
The only way to do this (that I aware of) is with AppleScript. Open Script Editor, copy and paste the following into a blank document, and save it as an application named GetSelectedFolders.app:
on run
tell application "Finder"
copy selection to theSelected
set outputPathList to {}
repeat with anItem in theSelected
if kind of (anItem as alias) is "folder" then
copy (POSIX path of (anItem as alias)) to end of outputPathList
end if
end repeat
return outputPathList
end tell
end runimport os script_path = "osascript ~/path/to/GetSelectedFolders.app" selected_folders = [path.strip() for path in os.popen(script).readlines()] |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OnlineTextEditor.Com! | Sane | Show Off Your Open Source Projects | 43 | Jun 16th, 2006 8:55 AM |
| add mutiple users to the smbpasswd file. | Pizentios | Bash / Shell Scripting | 3 | Oct 20th, 2005 12:48 PM |
| After execution - Error cannot locate /Skin File? | wchar | Visual Basic | 1 | Mar 5th, 2005 9:04 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |
| Structure char field to a disk file | ehab_aziz2001 | C++ | 0 | Feb 10th, 2005 2:42 PM |