• 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: en-dash and em-dash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: en-dash and em-dash


  • Subject: Re: en-dash and em-dash
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 19 Jun 2016 19:17:43 -0500

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.


Hey Mitchell,

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.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# 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
-------------------------------------------------------------------------------------------

 _______________________________________________
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/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: AppleScript-Users Digest, Vol 13, Issue 262 (From: Mitchell L Model <email@hidden>)

  • Prev by Date: Re: Script Libraries
  • Next by Date: Re: Script Libraries
  • Previous by thread: Re: AppleScript-Users Digest, Vol 13, Issue 262
  • Next by thread: Re: AppleScripting in OmniGraffle
  • Index(es):
    • Date
    • Thread