6

I am using applescripts supplied by Araxis so that I can use Merge to handle my 'git diff HEAD` command.

However, ever since upgrading to Mountain Lion, each time I run the command, I receive the warning:

CFURLGetFSRef was passed this URL which has no scheme 
(the URL may not work with other CFURL routines): .

In the script, what seems to be causing the problem is

set _file2 to (POSIX path of (POSIX file "." as alias)) & _file2

When I hard-code the path instead of using ".", the warning goes away. I've tried pre-pending file:///, but POSIX path of is considering one of the slashes to be an escape character and so the path becomes file:/Users/... which then generates an error for being having an unknown schema (since the second slash was removed). So, my question is, what is the proper way (now, in Mountain Lion), to fetch the POSIX file for the current location?

adding full script

#!/usr/bin/osascript
# This script is required to reorder the parameters sent by Git, so that they may be passed into the Merge Applescript API
on run args
  tell application "Araxis Merge"
    set _file1 to item 2 of args as text
    set _file2 to item 5 of args as text  

    if not _file1 starts with "/"
      set _file1 to (POSIX path of (POSIX file "." as alias)) & _file1
    end if

    if not _file2 starts with "/"
      set _file2 to (POSIX path of (POSIX file "." as alias)) & _file2
    end if


    set _document to compare {_file1, _file2}

    tell _document
      activate
    end tell
    repeat while exists _document
      delay 1
    end repeat
  end tell
end run

working solution (thanks @adayzdone)

#!/usr/bin/osascript
# This script is required to reorder the parameters sent by Git, so that they may be passed into the Merge Applescript API
on run args
  tell application "Araxis Merge"
    set _file1 to item 2 of args as text
    set _file2 to item 5 of args as text  

    if not _file1 starts with "/"
      set _file1 to (POSIX path of (POSIX file (do shell script "pwd") as alias)) & _file1
    end if

    if not _file2 starts with "/"
      set _file2 to (POSIX path of (POSIX file (do shell script "pwd") as alias)) & _file2
    end if

    set _document to compare {_file1, _file2}

    tell _document
      activate
    end tell
    repeat while exists _document
      delay 1
    end repeat
  end tell
end run
sorens
  • 4,975
  • 3
  • 29
  • 52
  • I think you may have extra coercions. See if this works. set _file1 to ((do shell script "pwd") & _file1) – adayzdone Oct 08 '12 at 19:43
  • @adayzdone They are required. The case you inquire about would lead to a string (which would be missing a directory separator character) instead of a file alias pointing at the correct file. In any event, thanks for the help. The script now correctly opens the appropriate file in Araxis Merge and without the warning. – sorens Oct 08 '12 at 22:43

2 Answers2

6

osascript shows the warning every time a relative path is converted to an alias on 10.8.

$ touch test.txt
$ osascript -e 'POSIX file "test.txt" as alias'
2012-12-19 09:43:49.300 osascript[16581:707] CFURLGetFSRef was passed this URL which has no scheme (the URL may not work with other CFURL routines): test.txt
alias HD:private:tmp:test.txt

Here is another way to convert the paths:

osa() {
    osascript - "$PWD" "$@" <<'END'
on run argv
repeat with f in items 2 thru -1 of argv
if f does not start with "/" then set f to item 1 of argv & "/" & f
posix file f as alias
end
end
END
}

osa ~/Documents/ 1.txt

You could also just redirect stderr.

osa() {
    osascript - "$@" <<END 2> /dev/null
on run argv
POSIX file (item 1 of argv) as alias
end
END
}
osa test.txt
Community
  • 1
  • 1
Lri
  • 26,768
  • 8
  • 84
  • 82
  • `folder of (path to me)` returns `Can’t get folder of (path to me). Access not allowed.` Just `path to me` returns the path to the running script. What I need is the path to the current directory of the shell where the command is being run so that the filename that is passed to the script via the arguments can be turned into an alias. – sorens Oct 08 '12 at 12:22
3

What I need is the path to the current directory of the shell where the command is being run

Does this work for you?

set xxx to do shell script "pwd"
adayzdone
  • 11,120
  • 2
  • 20
  • 37
  • Aha! Yes, that was what I was looking for. I'll update the script in my question to show the working solution. Thanks. – sorens Oct 08 '12 at 17:47