set theURL to "file://localhost/Users/kel/Desktop/e%CC%81%C3%B8u%CC%88%C2%A5"
set posixPath to do shell script ("python" & " -c 'from sys import argv; from urlparse import urlparse; from urllib import unquote; print unquote(urlparse(argv[1])[2])' " & quoted form of theURL)
I tried to do it with urllib.unquote earlier and it didn’t work. Wonder how that other stuff made it work.
Edited: I think I was using unquote wrong. Yeah, I was using the whole url, but you need the parts of the tuple I think. Anyway,
Edited: Here’s the uncrunched version if you want. Still don’t understand the argv part.
set f to choose file
tell application "Finder" to set theURL to url of f
set py_text to "'
from sys import argv
from urlparse import urlparse
from urllib import unquote
print unquote(urlparse(argv[1])[2])' "
set py_com to ReplaceText(py_text, return, ASCII character 10)
set u_path to (do shell script "python -c " & py_com & quoted form of theURL)
set item_ref to u_path as POSIX file as alias
--
on ReplaceText(t, s, r)
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to s
set temp_list to text items of t
set AppleScript's text item delimiters to r
set temp_text to temp_list as string
set AppleScript's text item delimiters to utid
return temp_text
end ReplaceText
Edited: oh it’s the ‘print’ I was missing earlier. You could have just done this if you had the last part of the local file url (the name).
I’m saving the thread, but I’m lousy with shell scripting and I’m completely in the dark when it comes to Python (even though I know has ‘knows best’).
Just wanted to thank you both… I’ve got something I can ‘play with’ now, which is a whole lot more than I had before. I wouldn’t have had a prayer of working out a solution on my own… most shell scripting is entirely opaque to me… and probably always will be.
I found out what was puzzling me about the script. I was thinking the [2] was argv[2], but there was only 1 passed argument. I did some review with Python and now see clearly that it was a slice, the third item of the tuple, the path.