iWork Numbers · AppleScripts

Export Table to HTML

    An AppleScript to export an iWork Numbers table to HTML. The generated HTML code is put onto the clipboard. Unfortunately, not all the formatting information is available via AppleScript. It is e.g. not possible to detect automatic formatting or conditional formatting. Therefore, the less automatic formatting is used, the more accurate the result will be.

The script will ask for the sheet name and the table name (if there is more than one). Also, it asks you to specify the numbers of the title rows and columns since their automatically set font weight and alignment cannot be retrieved via AppleScript.

Let's take a look at an example. This is a screenshot of a Numbers table without any automatic formatting (file is included in the zip-download):

Screenshot of Export Table to HTML - original table


Exported to HTML with the currently used settings (check the top section of the source) the result will look like this:

TestTable
Project 1 Project 2 Percent Numbers
01.01.12 100,00 10,00 10,00 % 10,00
01.02.12 200,00 20,00 23,56 % 20,00
01.03.12 300,00 -60,00 80,35 % 30,00
01.04.12 400,00 30,00 87,60 % 45,68
01.05.12 -500,00 40,00 10,00 % -50,00
01.06.12 600,00 50,00 23,56 % 20,00
01.07.12 700,00 60,00 80,35 % 30,00
01.08.12 800,00 70,00 87,60 % 45,68
01.09.12 900,00 80,00 10,00 % -50,00
01.10.12 1000,00 90,00 23,56 % 20,00
01.11.12 1100,00 100,00 80,35 % 30,00
01.12.12 -500,00 110,00 87,60 % 111,23
5100,00 600,00 262,59


Currently, the following formatting options are supported:

The following formatting options cannot be detected:

And finally some tips for good results:

The Numbers file used for the example shown above is included in the download.

Let me know what you think and if this script was helpful to you.

Save the script to ~/Library/Scripts/Applications/Numbers/ and run it via the AppleScript Menu or use a third-party application like FastScripts to easily assign a keyboard shortcut to the script.


show source AppleScript Editor open download
--   Creation date:    Montag, 23. Januar 2012, 19:03:53
--   Created by:        ljr (http://applescript.bratis-lover.net)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                                     SETTINGS
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

property myName : "Numbers · Table to HTML"
property myVersion : "1.0"


--c-- formatting

--c--- number of decimal places to round to (all numbers)
property decimalPlaces : 2
--c--- currency to use for currency format
property defaultCurrency : "€"
--c--- use bold font in these rows and columns
--      title lines and columns are usually bold which is not shown in the cell property
--      and therefore needs to be specified manually. negativ integers are allowed.
--      empty means not title rows/colums
--      e.g. {1,-2,-1} => first, second to last and last line have bold font
--      specify default values here. script will promt every time
property defaultBoldRows : {1, -1}
property defaultBoldColumns : {1}
--c--- date format
--      %m, %d, %Y, %y (year in abbreviated form), %H, %M, %S
--      e.g. "%d.%m.%y %H:%M%S" => "23.01.12 19:03:53"
property dateFormat : "%d.%m.%y"
--c--- include table name as caption
property includeTableNameAsCaption : true
--c--- fill empty cells with this string
--      e.g. " "; 
--      format empty cells as text in order to keep them empty (else 0,00 will be inserted)
property fillEmptyCellsWith : ""


--c-- css styles

--c--- table
property tableStyle : "width:430px;margin-left:auto;margin-right:auto;" & ¬
        "border-collapse:collapse;font-size:10px;"
--c--- caption
property captionStyle : "caption-side:top;font-weight:bold;text-align:center;font-size:12px;"
--c--- additional table data style
--      text-align, vertical-align, font-style, font-weight, background-color, color are 
--      set automatically; must end with ";" if not empty
property addTdStyle : "border:1px solid #D6D6D6;"
--c--- default alignment
--      used if align is automatic; can be left, right, center or justify
property defaultAlignment : "left"


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                               DESCRIPTION
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

(*

An AppleScript to export an iWork Numbers table to HTML. The generated HTML
code is put onto the clipboard. Unfortunately, not all the formatting information
is available via AppleScript. It is e.g. not possible to detect automatic formatting
or conditional formatting. Therefore, the less automatic formatting is used, the
more accurate the result will be.

The script will ask for the sheet name and the table name (if there is more than
one). Also, it asks you to specify the numbers of the title rows and columns since
their automatically set font weight and alignment cannot be retrieved via AppleScript.

Currently, the following formatting options are supported:

- horizontal and vertical alignment of text
- bold and italic fonts
- font color and background color
- currency, percent, date, number and text

The following formatting options ___cannot___ be detected:

- conditional formatting
- bold font and centered text automatically used in title rows and columns
- underlined text
- cell border formatting

And finally some tips for good results:

- The less automatic formatting is used, the more accurate the result will be.
- Check the settings in the top section of the script and specify the number of
  decimal places (used for all numbers), your currency and your preferred date format.
- Specify whether or not the table name should be included as caption.
- Adjust the _css styles_ section to your likings.
- Empty cells should be formatted as text in order to keep them empty
  (if not, they are filled with 0.00).
- You may want to specify the default numbers of your title rows and columns.
  The script will prompt for the numbers of title rows and columns every time.
- If you use any conditional formatting, make sure to transfer the formats before
  exporting.

WWW: http://applescript.bratis-lover.net/applescripts/iwork-numbers/export-table-to-html/
*)

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                                            MAIN
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

global _string, _math

tell application "Numbers"
        tell document 1
                
                --c- prompt for sheet (if more than one sheet exists)
                set sheetList to name of sheets
                set len to count sheetList
                if len > 1 then
                        set sheetName to choose from list sheetList with title myName ¬
                                with prompt "Please choose a sheet" OK button name ¬
                                "Continue" cancel button name "Cancel"
                        if class of sheetName is not list then return
                        set sheetName to (sheetName as string)
                else
                        set sheetName to sheetList's item 1
                end if
                
                tell sheet sheetName
                        
                        --c- prompt for table to convert (if more than one table exists)
                        set tableList to name of tables
                        set len to count tableList
                        if len > 1 then
                                set tableName to choose from list tableList with title myName ¬
                                        with prompt "Please choose the table to convert" OK button name ¬
                                        "Continue" cancel button name "Cancel"
                                if class of tableName is not list then return
                                set tableName to (tableName as string)
                        else
                                set tableName to tableList's item 1
                        end if
                        
                        --c- prompt for title rows
                        set txt to _string's implode(", ", defaultBoldRows)
                        set txt to text returned of (display dialog ¬
                                "Enter title rows as integers\n(comma separeted, negative " & ¬
                                "values allowed, leave empty for none)" default answer txt ¬
                                with title myName with icon 1)
                        set txt to _string's trimBoth(txt)
                        if txt is "" then
                                set boldRows to {}
                        else
                                set boldRows to _string's explode(",", txt)
                        end if
                        copy boldRows to defaultBoldRows
                        
                        --c- prompt for title columns
                        set txt to _string's implode(", ", defaultBoldColumns)
                        set txt to text returned of (display dialog ¬
                                "Enter title columns as integers\n(comma separeted, negative " & ¬
                                "values allowed, leave empty for none)" default answer txt ¬
                                with title myName with icon 1)
                        set txt to _string's trimBoth(txt)
                        if txt is "" then
                                set boldColumns to {}
                        else
                                set boldColumns to _string's explode(",", txt)
                        end if
                        copy boldColumns to defaultBoldColumns
                        
                        
                        --c- get properties of table to convert
                        set tableProperties to properties of table tableName
                        set rowCount to tableProperties's row count
                        set columnCount to tableProperties's column count
                        
                        --c- adjust bold lists (translate negative entries)
                        set adjBoldRows to my adjustBoldList(boldRows, rowCount)
                        set adjBoldColumns to my adjustBoldList(boldColumns, columnCount)
                        
                        --c- convert table to HTML
                        set htmlString to "<table style=\"" & tableStyle & "\">" & linefeed
                        
                        --c-- set caption
                        if includeTableNameAsCaption then
                                set htmlString to htmlString & "<caption style=\"" & captionStyle & "\">"
                                set htmlString to htmlString & tableName & "</caption>" & linefeed
                        end if
                        
                        tell table tableName
                                repeat with i from 1 to rowCount
                                        set htmlString to htmlString & tab & "<tr>" & linefeed
                                        
                                        repeat with j from 1 to columnCount
                                                set cellProperties to properties of cell j of row i
                                                set htmlString to htmlString & tab & tab & ¬
                                                        "<td style=\"" & addTdStyle
                                                
                                                --c-- alignment
                                                set cellAlignment to cellProperties's alignment
                                                if cellAlignment = auto align then
                                                        set cellAlignment to defaultAlignment
                                                else if cellAlignment = left then
                                                        set cellAlignment to "left"
                                                else if cellAlignment = right then
                                                        set cellAlignment to "right"
                                                else if cellAlignment = justify then
                                                        set cellAlignment to "justify"
                                                else if cellAlignment = center then
                                                        set cellAlignment to "center"
                                                end if
                                                set htmlString to htmlString & "text-align:" & ¬
                                                        cellAlignment & ";"
                                                
                                                --c-- vertical alignment
                                                set cellVerticalAlignment to cellProperties's vertical alignment
                                                --display dialog cellVerticalAlignment
                                                if cellVerticalAlignment = center then
                                                        set cellVerticalAlignment to "middle"
                                                else if cellVerticalAlignment = top then
                                                        set cellVerticalAlignment to "top"
                                                else if cellVerticalAlignment = bottom then
                                                        set cellVerticalAlignment to "bottom"
                                                end if
                                                set htmlString to htmlString & "vertical-align:" & ¬
                                                        cellVerticalAlignment & ";"
                                                
                                                --c-- text color
                                                set textColor to cellProperties's text color
                                                set textColor to my rgbToHTML(textColor)
                                                set htmlString to htmlString & "color:" & textColor & ";"
                                                
                                                --c-- background color
                                                set backgroundColor to cellProperties's background color
                                                if backgroundColormissing value then
                                                        set backgroundColor to my rgbToHTML(backgroundColor)
                                                        set htmlString to htmlString & "background-color:" & ¬
                                                                backgroundColor & ";"
                                                end if
                                                
                                                --c-- font style
                                                set fontName to cellProperties's font name
                                                if fontName contains "Italic" then
                                                        set htmlString to htmlString & "font-style:italic;"
                                                end if
                                                
                                                --c-- font weight
                                                if fontName contains "Bold" or i is in boldRows or ¬
                                                        j is in boldColumns then
                                                        set htmlString to htmlString & "font-weight:bold;"
                                                end if
                                                
                                                --c-- cell value
                                                set cellValue to cellProperties's value
                                                set cellFormat to cellProperties's format
                                                try
                                                        
                                                        --c--- handle percent format
                                                        if cellFormat is percent then
                                                                set isNegative to false
                                                                if cellValue < 0 then
                                                                        set isNegative to true
                                                                        set cellValue to cellValue * -1
                                                                end if
                                                                set cellValue to _math's ¬
                                                                        round_truncate(cellValue * 100, decimalPlaces)
                                                                set cellValue to cellValue & " %"
                                                                if isNegative then set cellValue to "-" & cellValue
                                                                
                                                                --c--- handle currency format
                                                        else if cellFormat is currency then
                                                                set isNegative to false
                                                                if cellValue < 0 then
                                                                        set isNegative to true
                                                                        set cellValue to cellValue * -1
                                                                end if
                                                                set cellValue to _math's ¬
                                                                        round_truncate(cellValue, decimalPlaces)
                                                                set cellValue to cellValue & " " & defaultCurrency
                                                                if isNegative then set cellValue to "-" & cellValue
                                                                
                                                                --c--- handel date formats
                                                        else if class of cellValue is date then
                                                                set cellValue to my formatDate(cellValue, dateFormat)
                                                                
                                                                --c--- handle reals and empty text formatted cells
                                                        else if class of cellValue is real then
                                                                if cellValue = 0 and (cellFormat as string) is in ¬
                                                                        {"text", "«constant ****ctxt»"} then
                                                                        set cellValue to fillEmptyCellsWith
                                                                else
                                                                        set isNegative to false
                                                                        if cellValue < 0 then
                                                                                set isNegative to true
                                                                                set cellValue to cellValue * -1
                                                                        end if
                                                                        set cellValue to _math's ¬
                                                                                round_truncate(cellValue, decimalPlaces)
                                                                        if isNegative then set cellValue to "-" & cellValue
                                                                        
                                                                end if
                                                        end if
                                                        
                                                on error
                                                        set cellValue to cellValue as string
                                                end try
                                                
                                                --c-- fill cell with value
                                                set cellValue to cellValue as string
                                                set htmlString to htmlString & "\">" & cellValue
                                                set htmlString to htmlString & "</td>" & linefeed
                                                
                                        end repeat
                                        
                                        --c-- close line
                                        set htmlString to htmlString & tab & "</tr>" & linefeed
                                end repeat
                        end tell
                        
                        --c-- close table
                        set htmlString to htmlString & "</table>" & linefeed
                        
                        --        return cellProperties
                        --display dialog "" default answer (cellFormat as string)
                        
                end tell
        end tell
        
        --c- copy html string to clipboard
        set the clipboard to htmlString
        
        display dialog "Conversion done!\n\nHTML code has been copied to the clipboard." with icon ¬
                1 buttons {"Done"} default button 1 with title myName giving up after 25
        
end tell








-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                                                    HANDLERS
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --


on errorHandler(customMsg, eMsg, eNum)
        display dialog customMsg & "\r\rError: " & eNum default answer eMsg ¬
                buttons {"Cancel"} default button 1 cancel button 1 with icon 0 ¬
                with title myName giving up after 15
        error number -128
end errorHandler


on rgbToHTML(RGB_values)
        -- NOTE: this sub-routine expects the RBG values to be from 0 to 65535
        -- http://www.macosxautomation.com/applescript/sbrt/sbrt-04.html
        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 rgbToHTML

on adjustBoldList(lst, maxVal)
        -- convert negative values to row/column numbers
        local lst, maxVal, thisVal, i
        try
                set len to count lst
                repeat with i from 1 to len
                        set thisVal to lst's item i as integer
                        if thisVal < 0 then
                                set thisVal to maxVal + thisVal + 1
                        end if
                        set lst's item i to thisVal
                end repeat
                return lst
        on error eMsg number eNum
                error "Can't adjustBoldList: " & eMsg number eNum
        end try
end adjustBoldList


on formatDate(theDate, dateFormat)
        -- ljr (http://applescript.bratis-lover.net)
        local theDate, dateFormat, d, m, y, h, min, s
        try
                set d to _math's padNum(theDate's day, 2)
                set m to _math's padNum(theDate's month as integer, 2)
                set y to theDate's year as string
                set h to _math's padNum(theDate's hours, 2)
                set min to _math's padNum(theDate's minutes, 2)
                set s to _math's padNum(theDate's seconds, 2)
                set dateFormat to _string's replaceString(dateFormat, "%d", d)
                set dateFormat to _string's replaceString(dateFormat, "%m", m)
                set dateFormat to _string's replaceString(dateFormat, "%Y", y)
                set dateFormat to _string's replaceString(dateFormat, "%y", y's text 3 thru 4)
                set dateFormat to _string's replaceString(dateFormat, "%H", h)
                set dateFormat to _string's replaceString(dateFormat, "%M", m)
                set dateFormat to _string's replaceString(dateFormat, "%S", s)
                return dateFormat
        on error eMsg number eNum
                error "Can't formatDate: " & eMsg number eNum
        end try
end formatDate


script _math
        
        --c--   decPt()
        --d--   Get the decimal point separator as defined in system preferences.
        --r--   string -- "," or "."
        --u--   HAS (http://applemods.sourceforge.net/mods/Data/Math.php)
        on decPt()
                return character 2 of (0.0 as string)
        end decPt
        
        
        --c--   round_truncate(this_number, decimal_places)
        --d--   Round and truncate a number to the given decimal places.
        --a--   this_number : any number 
        --a--   decimal_places : integer 
        --r--   string
        --x--   round_truncate(1.2358E+9, 2) --> "1,24"
        --q--   number_to_string
        --u--   http://www.macosxautomation.com/applescript/sbrt/sbrt-02.html
        on round_truncate(this_number, decimal_places)
                local this_number, decimal_places, rounding_value
                local mod_value, second_part, first_part
                try
                        if decimal_places is 0 then
                                set this_number to this_number + 0.5
                                return my number_to_string(this_number div 1)
                        end if
                        set rounding_value to "5"
                        repeat decimal_places times
                                set rounding_value to "0" & rounding_value
                        end repeat
                        set rounding_value to (my decPt() & rounding_value) as number
                        set this_number to this_number + rounding_value
                        set mod_value to "1"
                        repeat decimal_places - 1 times
                                set mod_value to "0" & mod_value
                        end repeat
                        set mod_value to ("," & mod_value) as number
                        set second_part to (this_number mod 1) div mod_value
                        if length of (second_part as text) is less than decimal_places then
                                repeat decimal_places - (length of (second_part as text)) times
                                        set second_part to ("0" & second_part) as string
                                end repeat
                        end if
                        set first_part to this_number div 1
                        set first_part to my number_to_string(first_part)
                        set this_number to (first_part & my decPt() & second_part)
                        return this_number
                on error eMsg number eNum
                        error "Can't round_truncate: " & eMsg number eNum
                end try
        end round_truncate
        
        
        --c--   number_to_string(this_number)
        --d--   Convert number to string (usefull for  scientific notation).
        --a--   this_number : any number 
        --r--   string
        --x--   number_to_string(1.234E+9) --> "1234000000"
        --u--   http://www.macosxautomation.com/applescript/sbrt/sbrt-02.html
        on number_to_string(this_number)
                local this_number, decimal_adjust, first_part, second_part, converted_number
                try
                        set this_number to this_number as string
                        if this_number contains "E+" then
                                set x to offset of "," in this_number
                                set y to offset of "+" in this_number
                                set z to offset of "E" in this_number
                                set decimal_adjust to characters (y - (length of this_number)) thru ¬
                                        -1 of this_number as string as number
                                if x is not 0 then
                                        set first_part to characters 1 thru (x - 1) of this_number as string
                                else
                                        set first_part to ""
                                end if
                                set second_part to characters (x + 1) thru (z - 1) of this_number as string
                                set converted_number to first_part
                                repeat with i from 1 to decimal_adjust
                                        try
                                                set converted_number to ¬
                                                        the converted_number & character i of second_part
                                        on error
                                                set converted_number to converted_number & "0"
                                        end try
                                end repeat
                                return converted_number
                        else
                                return this_number
                        end if
                on error eMsg number eNum
                        error "Can't number_to_string: " & eMsg number eNum
                end try
        end number_to_string
        
        
        --c--   padNum(num, len)
        --d--   Convert positive integer to string padded with leading zeros
        --a--   num : integer -- number to pad
        --a--   len : integer -- pad length (2-8)
        --r--   string
        --x--   padNum(1, 3) --> "001"
        --u--   HAS (http://applemods.sourceforge.net/mods/Data/Math.php)
        on padNum(num, len)
                local num, len
                try
                        set num to num as integer
                        set len to len as integer
                        if num < 0 then error "number is negative." number -1704
                        if len < 2 or len > 8 then error "pad length is out of range (2-8)." number -1704
                        set num to num as string
                        if num's length > len then error "number is longer than pad length." number -1704
                        return text -len thru -1 of ("00000000" & num)
                on error eMsg number eNum
                        error "Can't padNum: " & eMsg number eNum
                end try
        end padNum
        
end script


script _string
        
        on replaceString(theText, oldString, newString)
                -- ljr (http://applescript.bratis-lover.net/library/string/)
                local ASTID, theText, oldString, newString, lst
                set ASTID to AppleScript's text item delimiters
                try
                        considering case
                                set AppleScript's text item delimiters to oldString
                                set lst to every text item of theText
                                set AppleScript's text item delimiters to newString
                                set theText to lst as string
                        end considering
                        set AppleScript's text item delimiters to ASTID
                        return theText
                on error eMsg number eNum
                        set AppleScript's text item delimiters to ASTID
                        error "Can't replaceString: " & eMsg number eNum
                end try
        end replaceString
        
        
        on explode(delimiter, input)
                -- ljr (http://applescript.bratis-lover.net/library/string/)
                -- modified from Applescript.net (http://bbs.applescript.net/viewtopic.php?id=18377)
                local delimiter, input, ASTID
                set ASTID to AppleScript's text item delimiters
                try
                        set AppleScript's text item delimiters to delimiter
                        set input to text items of input
                        set AppleScript's text item delimiters to ASTID
                        return input --> list
                on error eMsg number eNum
                        set AppleScript's text item delimiters to ASTID
                        error "Can't explode: " & eMsg number eNum
                end try
        end explode
        
        
        on implode(delimiter, pieces)
                -- ljr (http://applescript.bratis-lover.net/library/string/)
                -- modified from Applescript.net (http://bbs.applescript.net/viewtopic.php?pid=65358)
                local delimiter, pieces, ASTID
                set ASTID to AppleScript's text item delimiters
                try
                        set AppleScript's text item delimiters to delimiter
                        set pieces to "" & pieces
                        set AppleScript's text item delimiters to ASTID
                        return pieces --> text
                on error eMsg number eNum
                        set AppleScript's text item delimiters to ASTID
                        error "Can't implode: " & eMsg number eNum
                end try
        end implode
        
        
        on trimBoth(str)
                -- HAS (http://applemods.sourceforge.net/mods/Data/String.php)
                local str
                try
                        return my trimStart(my trimEnd(str))
                on error eMsg number eNum
                        error "Can't trimBoth: " & eMsg number eNum
                end try
        end trimBoth
        
        
        on trimEnd(str)
                -- HAS (http://applemods.sourceforge.net/mods/Data/String.php)
                local str, whiteSpace
                try
                        set str to str as string
                        set whiteSpace to {character id 10, return, space, tab}
                        try
                                repeat while str's last character is in whiteSpace
                                        set str to str's text 1 thru -2
                                end repeat
                                return str
                        on error number -1728
                                return ""
                        end try
                on error eMsg number eNum
                        error "Can't trimEnd: " & eMsg number eNum
                end try
        end trimEnd
        
        
        on trimStart(str)
                -- HAS (http://applemods.sourceforge.net/mods/Data/String.php)
                local str, whiteSpace
                try
                        set str to str as string
                        set whiteSpace to {character id 10, return, space, tab}
                        try
                                repeat while str's first character is in whiteSpace
                                        set str to str's text 2 thru -1
                                end repeat
                                return str
                        on error number -1728
                                return ""
                        end try
                on error eMsg number eNum
                        error "Can't trimStart: " & eMsg number eNum
                end try
        end trimStart
        
        
        
end script


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--c-                                                                            TERMS OF USE & CREDITS
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

(*
This script was written by ljr (http://applescript.bratis-lover.net).

Credits: 
- HAS (http://applemods.sourceforge.net) 
- http://www.macosxautomation.com

It is released under the following terms:

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*)