Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSIX file "." as alias causes "CFURLGetFSRef was passed this URL which has no scheme" warning

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
like image 429
sorens Avatar asked Oct 08 '12 07:10

sorens


2 Answers

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
like image 187
Lri Avatar answered Nov 11 '22 22:11

Lri


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"
like image 3
adayzdone Avatar answered Nov 11 '22 23:11

adayzdone