Posix Path script compatibility with Lion 10.7.3

Hi,
Since updating to Lion 10.7.3, an Applescript (generously created on this forum!) does not work any longer. The script allows to copy path to clipboard after adding a prefix:


on run {input, parameters}
	
	set itemPath to ""
	set uPath to ""
	tell application "Finder"
		activate
		set itemPath to selection as string
		set uPath to POSIX path of itemPath
		set uPath to "file://localhost" & uPath
		set the clipboard to uPath
	end tell
	
	return input
end run

Any help would be much appreciated :slight_smile:

Model: MacBook Pro (2010)
Browser: Safari 535.11
Operating System: Mac OS X (10.7)

Hi,

every Finder item has an URL property, it’s easier to use this


on run {input, parameters}
	
	set uPath to {}
	tell application "Finder"
		repeat with anItem in (get selection)
			set end of uPath to URL of anItem
		end repeat
	end tell
	set {TID, text item delimiters} to {text item delimiters, return}
	set the clipboard to (uPath as text)
	set text item delimiters to TID
	return input
end run


Thanks StefanK for such a quick response. And I think you were the author of my initial script…

Re the one you’re proposing, I replaced it in the Finder’s Services I had. But calling it for a given file gave me an Automator error. Do I need to edit it? (obviously not an Applescript expert!) In particular about this prefix I need for my TextMate Tasks Bundle (http://goo.gl/VYsnC) to be able to follow the path to a file…

Could you please clarify? Thank you

I’m certainly not the author. I’d have never written selection as string
this could cause problems if there is more than one file

As a service choose Service receives selected files or folders in Finder
and use this code


on run {input, parameters}
	set uPath to {}
	repeat with anItem in input
		tell application "Finder" to set end of uPath to URL of anItem
	end repeat
	set {TID, text item delimiters} to {text item delimiters, return}
	set the clipboard to (uPath as text)
	set text item delimiters to TID
	return input
end run

What is sure is that you kindly helped in the past; obviously not on that one :slight_smile:

I had the correct options selected for the Services (as I was using this before and it was working until 10.7.3). And I replaced the Applescript part with latest code you sent, with no success. Selecting the file, right-clicking and selecting this Services workflow gave me an error again.

Not sure what’s wrong…

In Lion Apple has changed the URL scheme of the Finder property
This works for me in 10.7.3

on run {input, parameters}
	set uPath to {}
	repeat with anItem in input
		set posixPathOfAnItem to POSIX path of anItem
		set end of uPath to "file://localhost" & posixPathOfAnItem
	end repeat
	set {TID, text item delimiters} to {text item delimiters, return}
	set the clipboard to (uPath as text)
	set text item delimiters to TID
	return input
end run 

Brilliant thank you!

Note that I wasn’t successful as a Service but changing it to an Application worked fine. Using LaunchBar, I can easily sent a file to a script/application, so I’m happy with that.

Thanks again!

It works also as a service in 10.7.3