on open {dropped_item}
tell application "Finder"
set the clipboard to "file://" & (URI Escape (POSIX path of the dropped_item))
end tell
end open
Saved as an application bundle, that gives you a way to drag-n-drop a file to get a Mail-friendly URI. You can drag the saved script into your Dock to keep it handy.on open {dropped_item}
set myString to (POSIX path of (the selection as alias))
set search_string to " "
set replacement_string to "%20"
my findReplace(myString, search_string, replacement_string)
tell application "Finder" to set the clipboard to "file:///" & theString
end open
(*============ SUBROUTINE ==============*)
on findReplace(theString, search_string, replacement_string)
if theString contains search_string then
set AppleScript's text item delimiters to search_string
set the text_item_list to text items of theString
set AppleScript's text item delimiters to replacement_string
set the theString to every item in text_item_list as Unicode text
set AppleScript's text item delimiters to ""
end if
return theString
end findReplace on open dropped_items set myList to "" repeat with anItem in dropped_items set myString to (POSIX path of (anItem as alias)) set search_string to " " set replacement_string to "%20" if myString contains search_string then set AppleScript's text item delimiters to search_string set the text_item_list to text items of myString set AppleScript's text item delimiters to replacement_string set the myString to every item in text_item_list as Unicode text set AppleScript's text item delimiters to "" end if set myList to myList & "file:///" & myString & return end repeat set the clipboard to myList end openIf that works, cool. If you want it as an app you run when you have files selected, it needs to look like this:
set theSel to (selection of application "Finder")
set pathList to ""
set search_string to " "
repeat with anItem in theSel
set myItem to (POSIX path of (anItem as alias))
if myItem contains search_string then
set myItem to (do shell script "echo " & quoted form of myItem & "|sed \"s/\\ /%20/g\"")
end if
set pathList to pathList & "file://" & myItem & return
end repeat
set the clipboard to pathList
That demonstrates an alternate approach to cleaning out the spaces by using sed with "do shell script."set my_arg to "foo" set helper_script to posix path of (path to me as text) & "Contents/Resources/Scripts/helper.rb" set script_output to do shell script helper_script & " --argument " & my_arg
smb://fileserver/blah/blah
Not sure if will help in your case.
posted by wongcorgi at 2:09 AM on July 8, 2008