On Jun 19, 2016, at 18:17, Mitchell L Model <email@hidden> wrote:
I mean they look like dashes in the window tab title but when I write that title to a text file from an AppleScript they turn into those weird characters.
Now that was absolutely vital information. (You were writing to a file...)
You have to specify the format you write to disk, or you get the old Mac OS Roman format by default.
------------------------------------------------------------------------------------------- # Vanilla AppleScript -------------------------------------------------------------------------------------------
set myFilePath to (path to desktop as text) & "Test.utf8.ccs.txt" set I_am_a_UTF8_Character_String to "This–String—Has–Some–ÜTF8-Characters…" writeUTF8(I_am_a_UTF8_Character_String, myFilePath)
set myFilePath to (path to desktop as text) & "Test.plain.ccs.txt" writeFilePlain(I_am_a_UTF8_Character_String, myFilePath)
------------------------------------------------------------------------------------------- --» writeUTF8() ------------------------------------------------------------------------------------------- -- Task: Write text to a file and overwrite any content. -- dMod: 2012/10/26 20:00 -- Note: Clone of write_to_file_overwriting ------------------------------------------------------------------------------------------- on writeUTF8(_text, _file) try if _file starts with "~/" then set _file to POSIX path of (path to home folder as text) & text 3 thru -1 of _file end if set fRef to open for access _file with write permission set eof of fRef to 0 write _text to fRef as «class utf8» close access fRef on error e number n try close access fRef on error e number n error "Error in writeUTF8() handler!" & return & return & e end try end try end writeUTF8 ------------------------------------------------------------------------------------------- on writeFilePlain(_text, _file) try if _file starts with "~/" then set _file to POSIX path of (path to home folder as text) & text 3 thru -1 of _file end if set fRef to open for access _file with write permission set eof of fRef to 0 write _text to fRef close access fRef on error e number n try close access fRef on error e number n error "Error in writeUTF8() handler!" & return & return & e end try end try end writeFilePlain
------------------------------------------------------------------------------------------- # AppleScriptObjC ------------------------------------------------------------------------------------------- # Auth: Christopher Stone { Heavy Lifting by Shane Stanley } # dCre: 2016/06/13 13:59 # dMod: 2016/06/13 14:14 # Appl: AppleScriptObjC # Task: Write UTF8 Text to a file – creating the directory path as required. # Libs: None # Osax: None # Tags: @Applescript, @Script, @Write, @UTF8, @Text, @File, @Create, @Make, @Directory, @Folder ------------------------------------------------------------------------------------------- use AppleScript version "2.4" -- Yosemite & later use framework "Foundation" use scripting additions -------------------------------------------------------------------------------------------
set fileContent to "This–String—Has–Some–ÜTF8-Characters…"
set fileName to "test file 01.txt" set newDirPath to POSIX path of ((path to desktop folder as text) & "test01:test02:") set newFilePath to newDirPath & fileName its createDirectoryAtPath:newDirPath its writeString:fileContent toPath:newFilePath
------------------------------------------------------------------------------------------- --» HANDLERS ------------------------------------------------------------------------------------------- on createDirectoryAtPath:thePath set {theResult, theError} to current application's NSFileManager's defaultManager()'s createDirectoryAtPath:thePath withIntermediateDirectories:true attributes:(missing value) |error|:(reference) if not (theResult as boolean) then set errorMsg to theError's localizedDescription() as text error errorMsg end if end createDirectoryAtPath: ------------------------------------------------------------------------------------------- on writeString:aString toPath:posixPath set anNSString to current application's NSString's stringWithString:aString anNSString's writeToFile:posixPath atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(missing value) end writeString:toPath: # Other encodings: NSMacOSRomanStringEncoding -------------------------------------------------------------------------------------------
|