C.O*_*.O. 5 macos shell applescript
我有一个程序可以生成 shell 脚本并通过 apple 脚本运行它。我的输出是 UTF-8 编码的,我无法更改它。在 OS X 10.6 及更高版本上运行良好。在 OS X 10.4 (Tiger) 上,只要我需要处理的文件名/路径包含变音符号,例如 \xc3\xa9、\xc3\xa0、\xc3\x9c 等,我的脚本就会失败。(我没有10.5 尝试一下,所以我还不知道那个)
\n\n我认为这是区域设置的问题。
\n\ndo shell script "locale" \nRun Code Online (Sandbox Code Playgroud)\n\n给我:
\n\n"LANG=\nLC_COLLATE=\\"C\\"\nLC_CTYPE=\\"C\\"\nLC_MESSAGES=\\"C\\"\nLC_MONETARY=\\"C\\"\nLC_NUMERIC=\\"C\\"\nLC_TIME=\\"C\\"\nLC_ALL="\nRun Code Online (Sandbox Code Playgroud)\n\n所以我想开始我的脚本:
\n\nexport LC_ALL=en_US.UTF-8;\nexport LANG=en_US.UTF-8;\nRun Code Online (Sandbox Code Playgroud)\n\n可能会有所帮助,但事实证明它仍然不起作用。
\n\n我还能做些什么来使 utf-8 编码的 shell 脚本在 OS X 10.4 上工作\n我可以让 UTF-8 以其他方式工作吗?或者我可以将其转换为系统使用的默认字符编码吗?
\n\n编辑:
\n\n事实证明,从我想到的导出语句开始:
\n\nexport LC_ALL=en_US.UTF-8;\nexport LANG=en_US.UTF-8;\nRun Code Online (Sandbox Code Playgroud)\n\n确实回答了我原来的问题。
\n\n这有效:
\n\ndo shell script " export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; touch /\xc3\xbc"\nRun Code Online (Sandbox Code Playgroud)\n\n我的问题是我需要使用 osascript 才能立即将 shell 返回到生成它的进程,如下所示:
\n\nset myScriptAsString to "do shell script \\" export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; touch /\xc3\xbc\\""\ndo shell script "export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; osascript -e " & quoted form of myScriptAsString & " > /dev/null 2> /dev/null & "\nRun Code Online (Sandbox Code Playgroud)\n\n无论我将导出放在哪里,它都不适用于 osascript...
\n在OS X 10.5上没有问题
\n\n当字符串包含扩展 ASCII 字符时, OS X 10.4osascript上的命令无法正确处理 UTF-8 编码文本。
解决办法:使用MacRoman编码,osascript处理没有问题。
set myScriptAsString to quoted form of "do shell script \\"touch /\xc3\xbc\\""\ndo shell script "tString=$(echo " & myScriptAsString & "| iconv -t MACROMAN -f UTF8-MAC); osascript -e \\"$tString\\" > /dev/null 2> /dev/null & "\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
2957 次 |
| 最近记录: |