• 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
[ALERT:Possible Phishing] Re: convert text data to PDF
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ALERT:Possible Phishing] Re: convert text data to PDF


  • Subject: [ALERT:Possible Phishing] Re: convert text data to PDF
  • From: Shane Stanley <email@hidden>
  • Date: Fri, 18 Sep 2015 18:22:39 +1000

On 18 Sep 2015, at 10:28 AM, Shane Stanley <email@hidden> wrote:

Perhaps I misunderstood.

And indeed I did -- the body property returns HTML text. It turns out that body is in the scripting dictionary, but incorrectly, so it doesn't show up in a search. Once you find it (or try it), things become clearer.

So having found that, let's try:

use scripting additions
use framework "Foundation"
use framework "AppKit"

tell application "Notes"
set theBody to body of note 2
set theName to name of note 2 -- for file name
end tell
-- make NSString
set anNSString to current application's NSString's stringWithString:theBody
-- get string as raw data
set theData to anNSString's dataUsingEncoding:(current application's NSUTF8StringEncoding)
-- make into styled string
set styledString to current application's NSAttributedString's alloc()'s initWithHTML:theData documentAttributes:(missing value)
-- get page size being used for printing
set printInfo to current application's NSPrintInfo's sharedPrintInfo()
set pageSize to printInfo's paperSize()
set theLeft to printInfo()'s leftMargin()
set theTop to printInfo()'s topMargin()
-- make a text view
set theView to current application's NSTextView's alloc()'s initWithFrame:{origin:{x:0, y:0}, |size|:pageSize}
theView's setTextContainerInset:{theLeft, theTop}
-- put in the text
theView's textStorage()'s setAttributedString:styledString
set theData to theView's dataWithPDFInsideRect:{origin:{x:0, y:0}, |size|:pageSize}
-- build path based on title
set theName to current application's NSString's stringWithString:theName
set theName to theName's stringByReplacingOccurrencesOfString:"/" withString:"_"
set theName to theName's stringByReplacingOccurrencesOfString:":" withString:"_"
set thePath to current application's NSString's stringWithString:(POSIX path of (path to desktop))
set thePath to (thePath's stringByAppendingPathComponent:theName)'s stringByAppendingPathExtension:"pdf"
theData's writeToFile:thePath atomically:true

For some reason the HTML doesn't specify a font unless something other than the default is set in Notes, and it won't include attachments, so you may still see formatting differences.

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

 _______________________________________________
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

  • Follow-Ups:
    • Re: [ALERT:Possible Phishing] convert text data to PDF
      • From: Steve Mills <email@hidden>
References: 
 >convert text data to PDF (From: Yvan KOENIG <email@hidden>)
 >Re: convert text data to PDF (From: Shane Stanley <email@hidden>)
 >Re: convert text data to PDF (From: Yvan KOENIG <email@hidden>)
 >Re: convert text data to PDF (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Web Renderer (URL -> image)
  • Next by Date: Re: Web Renderer (URL -> image)
  • Previous by thread: Re: convert text data to PDF
  • Next by thread: Re: [ALERT:Possible Phishing] convert text data to PDF
  • Index(es):
    • Date
    • Thread