• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AppleScript with Japanese filenames
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript with Japanese filenames


  • Subject: Re: AppleScript with Japanese filenames
  • From: kai <email@hidden>
  • Date: Wed, 25 Oct 2006 23:06:51 +0100


On 25 Oct 2006, at 11:02, apparao wrote:

I have a sample JPG file with name 新しいノート.jpg placed on Desktop. I want to send that file as a mail attachment to some body. For that i wrote the following script:

[snip: script]

English version is working fine and not with Japanese file names.

Am i doing any thing wrong in Apple script (or) Is Apple script, not supports Japanese filenames?

I see that both Peter and Chris have beaten me to it. FWIW, here's part of something I started earlier (with some now redundant explanation snipped)...


As we've seen, one way around this is to avoid specifying the file path/name at compile time, by choosing the file to attach at runtime.

--------------------

set f to choose file
set s to "some name <email@hidden>"
set n to (info for f)'s name
set p to f's POSIX path

tell application "Mail"
	tell (make new outgoing message with properties ¬
		{sender:s, subject:n, visible:true}) to make ¬
		attachment with properties {file name:p}
	activate
end tell

--------------------

If you really need to specify the file by name, another approach might be to use raw Unicode data:

--------------------

set s to "some name <email@hidden>"
set n to «data utxt65B03057304430CE30FC30C8002E006A00700067»
set p to POSIX path of (path to desktop) & n

tell application "Mail"
	tell (make new outgoing message with properties ¬
		{sender:s, subject:n, visible:true}) to make ¬
		attachment with properties {file name:p}
	activate
end tell

--------------------

But how does one determine the relevant data in the first place?

I use a converter script (below) that I cobbled together a while back. Simply copy the required text (in this case, from the file in question) and paste it into the text entry dialog that appears. The Unicode data should then be copied to the clipboard, in a form suitable for pasting straight into your script editor:

--------------------

property hex : {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}

on utxt_data from t given coercing:c
	set n to count t
	if n is 0 then error number -128
	set r to "«data utxt"
	set q to "» as unicode text"'s text 1 thru (1 - 2 * (c as integer))
	if n > 63 then
		set n to 63
		set q to q & " & " & (utxt_data from t's ¬
			text 64 thru -1 without coercing)
		set t to t's text 1 thru n
	end if
	set n to n * 2
	script o
		property l : ({{t:t}} as text)'s characters -n thru -1
	end script
	repeat with i from 1 to n
		tell (ASCII number (o's l's item i)) to set o's l's item i to my ¬
			hex's item (it div 16 + 1) & my hex's item (it mod 16 + 1)
	end repeat
	r & o's l & q
end utxt_data

set text item delimiters to {""}
set the clipboard to (utxt_data from text returned of (display dialog ¬
	"Enter or paste the text to copy as Unicode data:"; default answer ¬
	return buttons {"Cancel", "Copy"} default button 2) with coercing)

--------------------

When writing a script, there's a limit to how much data can be packed into each raw code, so the above routine converts (where necessary) in chunks. This should avoid a potential compile time error: number -2742 (indicating that a token is too long to be parsed).

However, those who haven't yet seen the message that accompanies such an error might enjoy this:

--------------------
set d to "0"
repeat 8 times
	set d to d & d
end repeat
run script "«data utxt" & d & "»"
--------------------

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden
References: 
 >AppleScript with Japanese filenames (From: apparao <email@hidden>)

  • Prev by Date: Re: Entourage Rule to modify incoming email message source
  • Next by Date: Re: Entourage Rule to modify incoming email message source
  • Previous by thread: Re: AppleScript with Japanese filenames
  • Next by thread: Re: "~" vs. "POSIX file"
  • Index(es):
    • Date
    • Thread