Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'simple explanation' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
simple explanation
Authored by: mzs on May 02, '06 07:34:33PM
I just figured-out how to post to macosxhints.com using Polish characters. Therefore I think I can more simply explain what this hint is all about, since there seems to be some confusion. This web page shows a bunch of Central European international characters. Suppose you have this AppleScript named shebang.applescript:

set argv to do shell script "/bin/cat"

set AppleScript's text item delimiters to ASCII character 0
set argv to my argv's text items
And this shell script named shebang:

#!/bin/sh

{
	nullsep=''
        for arg in "$@"; do
                echo -ne "$nullsep"; echo -nE "$arg"
		nullsep='\x00'
        done
} | exec /usr/bin/osascript -- "$0".applescript
Then this works:

$ /bin/sh shebang 1 2 3 4
1, 2, 3, 4
$ /bin/sh shebang ? ?
?, ?
$ /bin/sh shebang ? ? | xxd
0000000: c581 2c20 c582 0a                        .., ...
c5 81 is the hex for "LATIN CAPITAL LETTER L WITH STROKE"
c5 82 is the hex for "LATIN SMALL LETTER L WITH STROKE"

This works correctly, all of the other methods of passing arguments to AppleScript from the command line that I know of munge the arguments according to your character encoding, in my case macroman.

The rest of the hint is about the following:

  • How to have the same file contain both a shell script and an AppleScript.
  • How to have the same file contain both a shell script and a compiled AppleScript (so that it does not need to be compiled each time it is run).
  • Useful Makefile rules to utilize the recipes for the above two items plus magic shebang lines to use so that you can run any AppleScript from the command line.
  • A few helpful examples along the way
  • Some notes about dead ends that did not work.


[ # ]
argh, macosxhints stripped-away my Polish characters
Authored by: mzs on May 02, '06 07:36:43PM
Here is the terminal interaction with the international characters again:

$ /bin/sh shebang 1 2 3 4
1, 2, 3, 4
$ /bin/sh shebang Ł ł
Ł, ł
$ /bin/sh shebang Ł ł | xxd
0000000: c581 2c20 c582 0a                        .., ...


[ # ]