• 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: Syntax highlighting, compilation etc.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Syntax highlighting, compilation etc.


  • Subject: Re: Syntax highlighting, compilation etc.
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 25 Apr 2017 10:36:24 +1000

On 25 Apr 2017, at 10:13 am, Jean-Christophe Helary <email@hidden> wrote:

Or are you telling me that the rich text is always created on the fly when opening a compiled file as the code you sent yesterday seemed to suggest ?

Yes. AppleScript uses the script, which contains four-letter codes for all the terminology, plus the dictionaries of any apps, libraries and scripting additions addressed to find out what those codes stand for, and then generates the source you see.

I just want to extract some rtf from somewhere, possible without using too many fancy tools.

An attributed string can be converted to rtf simply enough. But it's not *extracting*, it's *generating*.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set thePath to POSIX path of (choose file) -- chose script
set theDest to POSIX path of (path to desktop) & "Test.rtf"
set theURL to current application's |NSURL|'s fileURLWithPath:thePath
set {theScript, errorDict} to current application's NSAppleScript's alloc()'s initWithContentsOfURL:theURL |error|:(reference)
if theScript is missing value then error (errorDict's |description|() as text)
set styledSource to theScript's richTextSource()
set theRTF to styledSource's RTFFromRange:{0, styledSource's |length|()} documentAttributes:(missing value)
theRTF's writeToFile:theDest atomically:true

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
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: 
 >Syntax highlighting, compilation etc. (From: Jean-Christophe Helary <email@hidden>)
 >Re: Syntax highlighting, compilation etc. (From: Shane Stanley <email@hidden>)
 >Re: Syntax highlighting, compilation etc. (From: Jean-Christophe Helary <email@hidden>)
 >Re: Syntax highlighting, compilation etc. (From: Shane Stanley <email@hidden>)
 >Re: Syntax highlighting, compilation etc. (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: Re: TextEdit things
  • Next by Date: Which Messages event is supposed to fire when image is received?
  • Previous by thread: Re: Syntax highlighting, compilation etc.
  • Next by thread: Which Messages event is supposed to fire when image is received?
  • Index(es):
    • Date
    • Thread