MACSCRPT Archives

June 2008

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Nobumi Iyanaga <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Mon, 2 Jun 2008 11:16:49 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (92 lines)
Hello,

I am having problems with file names with a "FULLWIDTH  
TILDE" (0xFF5E). Here is how you can reproduce the problem.

Make a folder in which you have one or more files. Then rename one of  
the files with a name having in it the "FULLWIDTH TILDE" (0xFF5E)  
character ('~') -- note that if you use a Japanese input method (I  
am using EGBridge, but I think you will have the same result with  
other Japanese input methods) and type normally "〜", you will get  
"WAVE DASH" (0x301C) ('〜'), which seems the same as the "FULLWIDTH  
TILDE" (0xFF5E), but is a different character. To get the "FULLWIDTH  
TILDE" (0xFF5E), you can either use the "copy and paste" method, or  
use UnicodeChecker, etc.

Now, try to run the following script:

set theFolder to "Macintosh HD:Users:you:Desktop:your_test_folder:"
set theFolder to theFolder as alias
tell application "Finder"
	set allFiles to every item of theFolder
end tell

set fnames to {}
repeat with i in allFiles
	set fnames to fnames & (i as Unicode text)
end repeat

repeat with i in fnames
	my setfilecomment(i, "abced")
end repeat


on setfilecomment(thefile, thecomment)
	set thefile to thefile as alias
	tell application "Finder"
		set (comment of thefile) to thecomment
	end tell
	return thecomment
end setfilecomment

The script will stop at the line "set thefile to thefile as alias",  
with the error message (for example): "File Macintosh  
HD:Users:you:Desktop:your_test_folder:aiueo 〜 kakikukeko 〜.txt  
wasn't found."

It seems that when I convert the alias into "Unicode text", the  
character "FULLWIDTH TILDE" (0xFF5E) is wrongly converted into "WAVE  
DASH" (0x301C), and this is the reason why this script does not work.

If "FULLWIDTH TILDE" is really the only problematic character, I  
would probably be able to work around the problem (*), but I can not  
be sure.

Does anyone know if this is really the only case in which such a  
problem occurs?

(I am using OS 10.4.11 -- Perhaps this problem is fixed in  
Leopard...??).

Thank you very much in advance.

Best regard,

Nobumi Iyanaga
Tokyo,
Japan

(*) I tried this:

on setfilecomment(thefile, thecomment)
	try
		set thefile to thefile as alias
	on error number errNum
		if errNum is -43 then
			set temp to "" as Unicode text
			set temp to temp & my WAVE_DASH2FULLWIDTH_TILDE(thefile)
			set thefile to temp
                  ...

and

on WAVE_DASH2FULLWIDTH_TILDE(str)
	set res to "" as Unicode text
	set res to res & (do shell script "/usr/bin/perl -e 'use utf8;  
binmode (STDOUT, \":utf8\"); $_ = shift; s/\\x{301C}/\\x{FF5E}/g;  
print;'" & space & quoted form of str)
	return res
end WAVE_DASH2FULLWIDTH_TILDE

But WAVE_DASH2FULLWIDTH_TILDE returns garbled characters "ï1⁄2û"  
instead of "FULLWIDTH TILDE" -- so this work-around does not work...!

ATOM RSS1 RSS2