Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 2nd, 2007, 4:41 PM   #1
poopman
Newbie
 
Join Date: Feb 2007
Posts: 13
Rep Power: 0 poopman is on a distinguished road
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:
poopman is offline   Reply With Quote
Old Feb 2nd, 2007, 6:02 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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?
titaniumdecoy is offline   Reply With Quote
Old Feb 2nd, 2007, 6:06 PM   #3
poopman
Newbie
 
Join Date: Feb 2007
Posts: 13
Rep Power: 0 poopman is on a distinguished road
Thanks for replying back. I'm asking how to determine the path of the directory currenttly selected in the finder.
poopman is offline   Reply With Quote
Old Feb 2nd, 2007, 8:59 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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 run
You can now call this AppleScript from within your Python code. The result (selected_folders in the code below) will be a list of filepaths.

import os
script_path = "osascript ~/path/to/GetSelectedFolders.app"
selected_folders = [path.strip() for path in os.popen(script).readlines()]
Hope that helps! You might find this post useful as well.
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:04 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC