1

I am trying to do a rather simple thing: in the context menu I want to have an action (e.g. with Automator) that gets and copies the file's NSURL to clipboard.

The solution seems simple, but it does not work (some unspecific error). Here is what I have so far:

on run {input, parameters}

   set p to POSIX path of (input)
   set nsu to current application's |NSURL|'s fileURLWithPath:p

   return nsu

end run

I am looking to get the file reference URL, like so: file:///.file/id=6571367.2773272/

I am on El Capitan.

Any ideas?

  • Cheat and use PathFinder rather than Finder – Mark Oct 14 '15 at 13:55
  • 1
    I have added an answer, but it may be better if you clarify what you are really after and why.. – markhunte Oct 14 '15 at 16:48
1

Here is the solution to the issue (from: http://macscripter.net/viewtopic.php?pid=183164#p183164):

use framework "Foundation"

on run {input, parameters}

    set p to POSIX path of (input)
    set nsu to current application's |NSURL|'s fileURLWithPath:p

    set fru to nsu's fileReferenceURL()'s absoluteString() as text

    return fru

end run

I did not check jweak's answer. It may also work, after all. The poster over at macscripter also mentioned something important: input may contain a list of items (multi-selected).

Hope this helps someone.

-1

If you lose the parameters parameter, leaving only input, and if you start the script declaring the framework, it works.

use framework "Foundation"
on run {input}
   set p to POSIX path of (input)
   set nsu to current application's |NSURL|'s fileURLWithPath:p

   return nsu
end run

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .