• 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 --> HTML
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript --> HTML


  • Subject: Re: AppleScript --> HTML
  • From: Jean-Baptiste LE STANG <email@hidden>
  • Date: Fri, 25 Jul 2003 14:11:57 +0200

You can read the formating from cat com.apple.applescript.plist


You can also use the command ASFormat that comes with the script editor Smile.

@+ jb

The following will create a CSS for Applescript, you must use Smile to get the result. the RBG2HTML(RGB_values) comes from Apple. but it would ot be very difficult to parse the .plist so that you can use SD or SE


set theStyleList to {}
set theStyleName to {"uncompiled", "normal", "lang_keyword", "app_keyword", "comment", "literal", "user_symbol", "reference"}

repeat with x from 1 to 8
set end of theStyleList to ASFormat x
end repeat

set theCSS to ""

repeat with x from 1 to 8
set theCSS to theCSS & "." & item x of theStyleName & return & "{" & return & "font-family:" & font of item x of theStyleList & ";" & return & "font-size:" & text size of item x of theStyleList & "px;" & return & "font-color:" & RBG2HTML(color of item x of theStyleList) & ";" & return
if italic is in style of item x of theStyleList then set theCSS to theCSS & "font-style: italic;" & return
if bold is in style of item x of theStyleList then set theCSS to theCSS & "font-weight: bold;" & return
set theCSS to theCSS & "}" & return
end repeat


on RBG2HTML(RGB_values)
-- NOTE: this sub-routine expects the RBG values to be from 0 to 65536
set the hex_list to ,
{"0", "1", "2", "3", "4", "5", "6", "7", "8", ,
"9", "A", "B", "C", "D", "E", "F"}
set the the hex_value to ""
repeat with i from 1 to the count of the RGB_values
set this_value to (item i of the RGB_values) div 256
if this_value is 256 then set this_value to 255
set x to item ((this_value div 16) + 1) of the hex_list
set y to item (((this_value / 16 mod 1) * 16) + 1) of the hex_list
set the hex_value to (the hex_value & x & y) as string
end repeat
return ("#" & the hex_value) as string
end RBG2HTML

tell application "Finder" to set theFile to (make new file at desktop with properties {name:"applescript_css.html"}) as alias
open for access theFile with write permission
write theCSS to theFile
close access theFile


Le vendredi, 25 jul 2003, ` 13:36 Europe/Paris, Nigel Smith a icrit :

On 25/7/03 0:44, "John Delacour" <email@hidden> wrote:

If you're using Script Editor 2.0, you can get more style info than
you need and use this as a basis for your html.


get properties of words in paragraph 2 of document "Untitled"

It's a shame that the "style" of the words are based on attribute runs with
"characteristics", and don't include "what" those words are -- variable,
application keyword, and so on.

I had hoped to use:
set formatList to ""
set fileRef to POSIX path of alias <nobreak>
((path to preferences as text) & "com.apple.applescript.plist")
set formatList to every paragraph of (do shell script "cat " & <nobreak>
fileRef & " | sed -n <nobreak>
's/\\(<string>\\)\\(.*\\)\\(<\\/string>\\)/\\2/p' | cut -f3")
return formatList

...to find the AppleScript formatting and match that to the attribute run
properties, but that may prove difficult for a general script -- for example
the font name/style is difficult to match. But for personal use I guess you
could hard code those into a script.

So, pull out all the attribute runs, wrap them in HMTL/CSS tags dependent on
what they are rather than what they look like, then write the HTML file.

Sound feasible?

(I had thought of saving/rewriting the formatting prefs, so as to start from
a known format, but they wouldn't take immediate effect on a recompile.
Bum.)

Later,

Nigel
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: AppleScript --> HTML
      • From: John Delacour <email@hidden>
References: 
 >Re: AppleScript --> HTML (From: Nigel Smith <email@hidden>)

  • Prev by Date: Disk Copy Script
  • Next by Date: Re: AppleScript --> HTML
  • Previous by thread: Re: AppleScript --> HTML
  • Next by thread: Re: AppleScript --> HTML
  • Index(es):
    • Date
    • Thread