Connecting to OS X from Linux

December 12, 2008

I’m done school for the semester, so hopefully that means I’ll have some more time to work on programming and the like. Yesterday I was trying to get my Ubuntu laptop to connect to my Mac OS X desktop. Accessing a networked OS X computer as a windows share is pretty easy under Ubuntu. But you can only see a few files. When networking OS X to OS X you can access pretty much the whole computer. I found a package called afpfs-ng that allows you to do essentially the same thing from Ubuntu. Unfortunately this program requires you to use the command line to connect. Once I figured it out I started making my own GUI interface for afpfs-ng. I used python and am just about finished. Here’s the source code so far:

#!/usr/bin/python

import Tkinterimport subprocessimport os.path

# Define input retrieve function for application inputdef retrieve_text(): global volume global mounted if mounted is 0:   afp_ip = afp_host.get()   username = user_name.get()   volume = volume_in.get()   password = pass_word.get()   if os.path.exists('\"/tmp/'+volume+"\"") != 1:     output_string = "mkdir \"/tmp/" + volume + "\""     retcode = subprocess.Popen(output_string, shell=True)   output_string = "mount_afp \"afp://" + username + ":" + password + "@" + afp_ip + "/" + volume + "\" \"/tmp/" + volume + "\"\n nautilus \"/tmp/" + volume + "\""   retcode = subprocess.Popen(output_string, shell=True)   mounted = 1

def unmount(): global mounted if mounted is 1:   retcode = subprocess.Popen("afp_client unmount \"/tmp/" + volume + "\"", shell=True)   mounted = 0

if __name__ == "__main__":

 volume = 0 mounted = 0

 # Create Window Object or Window Form app_win = Tkinter.Tk()

 # Create label object labeltitle = Tkinter.Label(app_win,text="Connect to AFP Server\n") labeltitle.pack()

 # Create label object label1 = Tkinter.Label(app_win,text="Host IP") label1.pack()

 # Create User Input Object afp_host = Tkinter.Entry(app_win) afp_host.pack()

 # Create label object label2 = Tkinter.Label(app_win,text="Username") label2.pack()

 # Create User Input Object user_name = Tkinter.Entry(app_win) user_name.pack()

 # Create label object label2a = Tkinter.Label(app_win,text="Password") label2a.pack()

 # Create User Input Object pass_word = Tkinter.Entry(app_win) pass_word.pack()

 # Create label object label3 = Tkinter.Label(app_win,text="Volume") label3.pack()

 # Create User Input Object volume_in = Tkinter.Entry(app_win) volume_in.pack()

 # Create Button Object app_button = Tkinter.Button(app_win,text="Connect",command=retrieve_text) app_button.pack()

 # Create Button Object unmount_button = Tkinter.Button(app_win,text="Unmount",command=unmount) unmount_button.pack()

 # Initialize Graphical Loop app_win.mainloop()

If you copy that into an empty text document, save it as “afp.py”, open a terminal, type “python ” and then drag the “afp.py” file into the terminal, you can run it. Of course, you’ll have to download afpfs-ng first. Your command line should look something like this:
dustin@dustin:~$ python '/home/dustin/afp.py'

I’m still working on adding some more features and packaging this in an easier to use manner.