# -*- coding: utf-8 -*-
import os
from urlparse import urlparse
from urllib import unquote
from ScriptingBridge import SBApplication
def finder_frontmost_visible_window_path():
finder = SBApplication.applicationWithBundleIdentifier_('com.apple.Finder')
windows = filter(lambda x:x.visible()==True, finder.windows())
if windows:
w = windows[0]
t = w.properties()['target']
u = t.properties()['URL']
p = urlparse(u).path
s = p.encode('ascii')
path = unquote(s).decode('utf-8')
else:
path = os.path.expanduser('~/Desktop/').decode('utf-8')
return path
print( finder_frontmost_visible_window_path() )