These are Script fragments to create and handle documents, mainly in InDesign.
Create a document |
These are more realistic scripts to create documents: setting margins measurement system and page parameters; and adding colours. (In the QXP version the shell script used to set the view scale can cause problems (if, for example, it includes a refresh rate---as it did in the session :-) ) |
tell application "Adobe InDesign CS2"
activate
--setup
set myMarginPrefs to a reference to margin preferences
tell myMarginPrefs
set {top, bottom, left, right} to {10, 20, 30, 40}
(* or set them individually by chosing any or all of, for example:
set top to 0
set bottom to 0
set left to 0
set right to 0*)
end tell
set tempdoc to make new document --gives us a reference to the document
tell tempdoc
set tempwindow to layout window 1
set myViewPreferences to view preferences
tell myViewPreferences
set horizontal measurement units to points
set vertical measurement units to points
end tell
set myDocPrefs to document preferences
tell myDocPrefs
set {pages per document, page orientation, page height, page width} to {1, portrait, 2016, 1584}
end tell
zoom layout window 1 given fit page
set transform reference point of tempwindow to top left anchor
if not (exists color "PANTONE 186 C") then
make new color with properties {model:spot, space:CMYK, color value:{0.0, 91.0, 76.0, 6.0}, name:"PANTONE 186 C"}
end if
if not (exists color "White") then
make new color with properties {model:spot, space:CMYK, color value:{0.0, 0.0, 0.0, 0.0}, name:"White"}
end if
end tell
end tell
|
property pageSize : {2016, 1584}
tell application "QuarkXPress"
activate
set tempdoc to make new document --gives us a reference to the document
tell tempdoc
set horizontal measure to points
set vertical measure to points
set page height to ((item 1 of pageSize) as text) & "¬Ýpt"
set page width to ((item 2 of pageSize) as text) & "¬Ýpt"
set top margin to "10 pt"
set bottom margin to "20 pt"
set left margin to "30 pt"
set right margin to "40 pt"
set page rule origin to {"0 pt", "0 pt"}
set view scale to (((last word of (do shell script "system_profiler SPDisplaysDataType | grep Resolution") as number) - 250) * 100 / (item 1 of pageSize))
if not (exists color spec "PANTONE 186 C" of tempdoc) then --if it’Äôs already there it’Äôll give an error
make new color spec at beginning with properties {class:color spec, CMYK color value:{0, 65535, 49151, 2621}, color type:"PANTONE® solid coated", name:"PANTONE 186 C", long name:"PANTONE 186 C"}
end if
if not (exists color spec "White" of tempdoc) then
make new color spec at end with properties {class:color spec, CMYK color value:{0, 0, 0, 0}, color type:"RGB type", name:"White", long name:"White"}
end if
end tell
end tell
|
Add Text |
These scripts add text to the previously created document: setting size, leading, tab stops etc. |
property typeFont : "Arial" & tab & "Bold" --this is just because I'm putting it on the web and the tab gets specified
property myText : "Hello" & tab & "Underworld!" & return & tab & tab & " Or do I just mean World again?"
tell application "Adobe InDesign CS2"
activate
--setup
set tempdoc to document 1 --gives us a reference to an existing document (use the previous step to roll your own)
tell tempdoc
if not (exists swatch "PANTONE 186 C" of tempdoc) then --if it's already there it'll give an error
make new color with properties {id:180, model:spot, space:CMYK, color value:{0.0, 91.0, 76.0, 6.0}, name:"PANTONE 186 C"}
end if
--the guts of the script
set tempbox to make text frame with properties {geometric bounds:{33.6, 132, 259.3, 1485.7}, fill color:"None", name:"sg", wrap:none, contents:myText}
set properties of every paragraph of tempbox to {applied font:typeFont, point size:50, leading:56, justification:left, tracking:0, fill color:swatch "PANTONE 186 C" of tempdoc, fill tint:100}
make new tab stop in every paragraph of tempbox with properties {position:265, alignment:left align}
make new tab stop in every paragraph of tempbox with properties {position:338, alignment character:" ", alignment:character align, leader:"."}
--the end of the guts of the script
end tell
end tell
|
property typeFont : "Arial"
property myText : "Hello" & tab & "Underworld!" & return & tab & tab & tab & " Or do I just mean World again?"
tell application "QuarkXPress"
activate
--setup
set tempdoc to document 1--gives us a reference to an existing document (use the previous step to roll your own)
tell tempdoc
if not (exists color spec "PANTONE 186 C" of tempdoc) then --if it's already there it'll give an error
make new color spec at beginning with properties {class:color spec, CMYK color value:{0, 65535, 49151, 2621}, color type:"PANTONE® solid coated", name:"PANTONE 186 C", long name:"PANTONE 186 C"}
end if
set temppage to page 1 of tempdoc
tell temppage
--the guts of the script
set tempbox to make text box at beginning with properties {class:text box, color:null, bounds:{33.6, 132, 259.3, 1485.7} as points rectangle}
tell tempbox
set temptext to make new paragraph at beginning with properties {font:typeFont, size:"50", leading:"56", style:bold}
set text of temptext to myText
set tab list of every story to {{justification:left justified, position:"265 pt"}, {justification:align on, align character:" ", fill character:".", position:"338 pt"}}
set color of every paragraph to "PANTONE 186 C"
end tell
--the end of the guts of the script
end tell
end tell
end tell
|
type fitting |
Script that will fit a paragraph into a single line. Useful with addresses etc. It sets the tracking to a predetermined amount then scales and tracks |
--the usual stuff so that the guts of the script will work
global deltatr
global deltahs
global breakpoint
global limitpoint
tell current record
set deltatr to repetition 1 of cell "parameters"
set deltahs to repetition 2 of cell "parameters"
set breakpoint to repetition 3 of cell "parameters"
end tell
set limitpoint to -100
tell application "Adobe InDesign CS2"
activate
--setup
set tempdoc to document 1
set myText to "This is a paragraph of type that goes on to more than one line"
tell tempdoc
set tempBox to make text frame with properties {geometric bounds:{130, 250, 250, 410}, fill color:"None", contents:myText}
set properties of every paragraph of tempBox to {applied font:"Arial", point size:24, leading:26, justification:left, tracking:0}
-- or
--set tempbox to text frame 1 of document 1
-- which would give us a reference to an existing texbox
--the guts of the script which will
--set tracking (and scaling) to remove second lines
tell tempBox
set countOPara to count of paragraphs
set k to 1
repeat while k ’â§ countOPara
if exists line 2 of paragraph k then
repeat while exists line 2 of paragraph k
set tr to tracking of paragraph k
if tr < breakpoint then
set hs to horizontal scale of paragraph k
if tr > limitpoint then
set tracking of paragraph k to tr - deltatr
end if
set horizontal scale of paragraph k to hs - deltahs
else
set tracking of paragraph k to tr - deltatr
end if
end repeat
end if
set k to k + 1
end repeat
end tell
end tell
end tell
|
Bar Code |
This draws a series of rectangles to make a Code128 Bar Code. It only works for a number. Remember to have an open document before running this. The first parameter above is the number The second is the size scale (try changing it to, say, 4). The third is the x and the fourth is the y coordinate. We also had to set the tell in the main section to the appropriate version of FMP (Pro or Advanced) |
-----------------------------C O D E 1 2 8-----------------------------
--THIS VERSION ONLY HANDLES NUMBERS!
--initialisation
--I got the lookup tables from the Code 128 specs
property myBarOrSpaceWidth : 0.6 -- Use to set basic width of bar or space in points
property myBarOrSpaceheight : 12 -- Use to set basic height of bar or space in points
-- multiply by same factor to make bars larger
--I don't think you are supposed to have them any smaller
------list for doCharacter. For each item: item1 is character; item2 is list of widths of bars alternating with spaces; item3 is value for checksum
property myNumLookupTable : {¬
{0, {1, 2, 3, 1, 2, 2}, 16}, ¬
{1, {1, 2, 3, 2, 2, 1}, 17}, ¬
{2, {2, 2, 3, 2, 1, 1}, 18}, ¬
{3, {2, 2, 1, 1, 3, 2}, 19}, ¬
{4, {2, 2, 1, 2, 3, 1}, 20}, ¬
{5, {2, 1, 3, 2, 1, 2}, 21}, ¬
{6, {2, 2, 3, 1, 1, 2}, 22}, ¬
{7, {3, 1, 2, 1, 3, 1}, 23}, ¬
{8, {3, 1, 1, 2, 2, 2}, 24}, ¬
{9, {3, 2, 1, 1, 2, 2}, 25}, ¬
{"startA", {2, 1, 1, 4, 1, 2}, 103}, ¬
{"Stop", {2, 3, 3, 1, 1, 1, 2}, 106} ¬
}
property myCheckSum : 0
-----list for doChecksum. For each item: item1 is value; item2 is character (not used by script-just there for the amusement of us poor sods); item3 is widths of bars alternating with spaces
property myLookupTable : {¬
{0, "SP", "2 1 2 2 2 2"}, ¬
{1, "!", "2 2 2 1 2 2"}, ¬
{2, "\"", "2 2 2 2 2 1"}, ¬
{3, "#", "1 2 1 2 2 3"}, ¬
{4, "$", "1 2 1 3 2 2"}, ¬
{5, "%", "1 3 1 2 2 2"}, ¬
{6, "&", "1 2 2 2 1 3"}, ¬
{7, "'", "1 2 2 3 1 2"}, ¬
{8, "(", "1 3 2 2 1 2"}, ¬
{9, ")", "2 2 1 2 1 3"}, ¬
{10, "*", "2 2 1 3 1 2"}, ¬
{11, "+", "2 3 1 2 1 2"}, ¬
{12, ",", "1 1 2 2 3 2"}, ¬
{13, "-", "1 2 2 1 3 2"}, ¬
{14, ".", "1 2 2 2 3 1"}, ¬
{15, "/", "1 1 3 2 2 2"}, ¬
{16, "0", "1 2 3 1 2 2"}, ¬
{17, "1", "1 2 3 2 2 1"}, ¬
{18, "2", "2 2 3 2 1 1"}, ¬
{19, "3", "2 2 1 1 3 2"}, ¬
{20, "4", "2 2 1 2 3 1"}, ¬
{21, "5", "2 1 3 2 1 2"}, ¬
{22, "6", "2 2 3 1 1 2"}, ¬
{23, "7", "3 1 2 1 3 1"}, ¬
{24, "8", "3 1 1 2 2 2"}, ¬
{25, "9", "3 2 1 1 2 2"}, ¬
{26, ":", "3 2 1 2 2 1"}, ¬
{27, ";", "3 1 2 2 1 2"}, ¬
{28, "<", "3 2 2 1 1 2"}, ¬
{29, "=", "3 2 2 2 1 1"}, ¬
{30, ">", "2 1 2 1 2 3"}, ¬
{31, "?", "2 1 2 3 2 1"}, ¬
{32, "@", "2 3 2 1 2 1"}, ¬
{33, "A", "1 1 1 3 2 3"}, ¬
{34, "B", "1 3 1 1 2 3"}, ¬
{35, "C", "1 3 1 3 2 1"}, ¬
{36, "D", "1 1 2 3 1 3"}, ¬
{37, "E", "1 3 2 1 1 3"}, ¬
{38, "F", "1 3 2 3 1 1"}, ¬
{39, "G", "2 1 1 3 1 3"}, ¬
{40, "H", "2 3 1 1 1 3"}, ¬
{41, "I", "2 3 1 3 1 1"}, ¬
{42, "J", "1 1 2 1 3 3"}, ¬
{43, "K", "1 1 2 3 3 1"}, ¬
{44, "L", "1 3 2 1 3 1"}, ¬
{45, "M", "1 1 3 1 2 3"}, ¬
{46, "N", "1 1 3 3 2 1"}, ¬
{47, "O", "1 3 3 1 2 1"}, ¬
{48, "P", "3 1 3 1 2 1"}, ¬
{49, "Q", "2 1 1 3 3 1"}, ¬
{50, "R", "2 3 1 1 3 1"}, ¬
{51, "S", "2 1 3 1 1 3"}, ¬
{52, "T", "2 1 3 3 1 1"}, ¬
{53, "U", "2 1 3 1 3 1"}, ¬
{54, "V", "3 1 1 1 2 3"}, ¬
{55, "W", "3 1 1 3 2 1"}, ¬
{56, "X", "3 3 1 1 2 1"}, ¬
{57, "Y", "3 1 2 1 1 3"}, ¬
{58, "Z", "3 1 2 3 1 1"}, ¬
{59, "[", "3 3 2 1 1 1"}, ¬
{60, "\"", "3 1 4 1 1 1"}, ¬
{61, "]", "2 2 1 4 1 1"}, ¬
{62, "^", "4 3 1 1 1 1"}, ¬
{63, "_", "1 1 1 2 2 4"}, ¬
{64, "NUL", "1 1 1 4 2 2"}, ¬
{65, "SOH", "1 2 1 1 2 4"}, ¬
{66, "STX", "1 2 1 4 2 1"}, ¬
{67, "ETX", "1 4 1 1 2 2"}, ¬
{68, "EOT", "1 4 1 2 2 1"}, ¬
{69, "ENQ", "1 1 2 2 1 4"}, ¬
{70, "ACK", "1 1 2 4 1 2"}, ¬
{71, "BEL", "1 2 2 1 1 4"}, ¬
{72, "BS", "1 2 2 4 1 1"}, ¬
{73, "HT", "1 4 2 1 1 2"}, ¬
{74, "LF", "1 4 2 2 1 1"}, ¬
{75, "VT", "2 4 1 2 1 1"}, ¬
{76, "FF", "2 2 1 1 1 4"}, ¬
{77, "CR", "4 1 3 1 1 1"}, ¬
{78, "SO", "2 4 1 1 1 2"}, ¬
{79, "SI", "1 3 4 1 1 1"}, ¬
{80, "DLE", "1 1 1 2 4 2"}, ¬
{81, "DC1", "1 2 1 1 4 2"}, ¬
{82, "DC2", "1 2 1 2 4 1"}, ¬
{83, "DC3", "1 1 4 2 1 2"}, ¬
{84, "DC4", "1 2 4 1 1 2"}, ¬
{85, "NAK", "1 2 4 2 1 1"}, ¬
{86, "SYN", "4 1 1 2 1 2"}, ¬
{87, "ETB", "4 2 1 1 1 2"}, ¬
{88, "CAN", "4 2 1 2 1 1"}, ¬
{89, "EM", "2 1 2 1 4 1"}, ¬
{90, "SUB", "2 1 4 1 2 1"}, ¬
{91, "ESC", "4 1 2 1 2 1"}, ¬
{92, "FS", "1 1 1 1 4 3"}, ¬
{93, "GS", "1 1 1 3 4 1"}, ¬
{94, "RS", "1 3 1 1 4 1"}, ¬
{95, "US", "1 1 4 1 1 3"}, ¬
{96, "FNC 3", "1 1 4 3 1 1"}, ¬
{97, "FNC 2", "4 1 1 1 1 3"}, ¬
{98, "SHIFT", "4 1 1 3 1 1"}, ¬
{99, "CODE C", "1 1 3 1 4 1"}, ¬
{100, "CODE B", "1 1 4 1 3 1"}, ¬
{101, "FNC 4", "3 1 1 1 4 1"}, ¬
{102, "FNC 1", "4 1 1 1 3 1"}, ¬
{103, "Start A", "2 1 1 4 1 2"}, ¬
{104, "Start B", "2 1 1 2 1 4"}, ¬
{105, "Start C", "2 1 1 2 3 2"}, ¬
{106, "Stop", "2 3 3 1 1 1 2"}}
global myStartHorizontal
global myStartVertical
global myCurrentHorizontal
global myCurrentVertical
global myText
global myChar
global myColour
global myColourValue
global myFactor
global myBackground
global j --counter
--end initialisation
--------------main-------------------------------
--set these from calling application
(*
e.g.
tell application "FileMaker Pro Advanced"
tell current record
set myColour to cell "colour"
set myText to cell "codeNumber"
set myFactor to cell "scaleFactor"
set myStartVertical to cell "vertStart"
set myStartHorizontal to to cell "horizStart"
end tell
end tell
or, in the current context, *)
tell application "FileMaker Pro Advanced"
tell current record
set myText to repetition 1 of cell "parameters"
set myFactor to repetition 2 of cell "parameters"
set myStartVertical to repetition 3 of cell "parameters"
set myStartHorizontal to (repetition 4 of cell "parameters")
set myColour to "PANTONE Reflex Blue U"
set myColourValue to {100.0, 73.0, 0.0, 2.0}
end tell
end tell
--end from calling application
set myBarOrSpaceWidth to myBarOrSpaceWidth * myFactor
set myBarOrSpaceheight to myBarOrSpaceheight * myFactor
set myCurrentHorizontal to myStartHorizontal
set myCurrentVertical to myStartVertical
my doBarBackground()
set j to 1
my doCharacter("startA")
set myCheckSum to 103
set myTextList to every text item of myText
repeat with thisText in myTextList
my doCharacter(thisText)
set j to j + 1
end repeat
my doChecksum(myCheckSum)
my doCharacter("Stop")
tell application "Adobe InDesign CS2"
set barGroup to make new group at parent of item 1 of selection with properties {group items:selection, name:"myBarCode"}
end tell
--------------end main---------------------------
--routines
on doBarBackground()
tell application "Adobe InDesign CS2"
activate
tell document 1
if not (exists swatch myColour) then --if it’Äôs already there it’Äôll give an error
make new color with properties {model:spot, color value:myColourValue, space:CMYK, name:myColour}
end if
set myBackground to make new rectangle with properties {fill color:swatch "Paper", stroke weight:0, stroke color:swatch myColour, geometric bounds:{myCurrentVertical - myFactor, myCurrentHorizontal - 9 * myFactor, myCurrentVertical + myBarOrSpaceheight + 4 * myFactor, myCurrentHorizontal + 9 * myFactor + ((count of text items in myText) + 3) * 11 * myBarOrSpaceWidth}}
end tell
end tell
end doBarBackground
on doCharacter(myChar)
tell application "Adobe InDesign CS2"
tell document 1
if myChar is "startA" then set myChar to 10
if myChar is "Stop" then set myChar to 11
set myPattern to item 2 of item (myChar + 1) of myNumLookupTable
set myCheckSum to myCheckSum + (item 3 of item (myChar + 1) of myNumLookupTable) * j
set i to 1
repeat with thisBarOrSpace in myPattern
if i mod 2 is 1 then
set myBar to make new rectangle with properties {fill color:swatch myColour, stroke weight:0, stroke color:swatch myColour, geometric bounds:{myCurrentVertical + 2, myCurrentHorizontal, myCurrentVertical + myBarOrSpaceheight + 2, myCurrentHorizontal + (myBarOrSpaceWidth * thisBarOrSpace)}}
select myBar existing selection add to
end if
set myCurrentHorizontal to myCurrentHorizontal + (myBarOrSpaceWidth * thisBarOrSpace)
set i to i + 1
end repeat
end tell
end tell
end doCharacter
on doChecksum(myCheckSum)
set myCheckSum to myCheckSum mod 103
tell application "Adobe InDesign CS2"
tell document 1
set myOldDelim to (text item delimiters of AppleScript)
set (text item delimiters of AppleScript) to " "
set myPattern to every text item of (item 3 of item (myCheckSum + 1) of myLookupTable)
set (text item delimiters of AppleScript) to myOldDelim
set i to 1
repeat with thisBarOrSpace in myPattern
if i mod 2 is 1 then
set myBar to make new rectangle with properties {fill color:swatch myColour, stroke weight:0, stroke color:swatch myColour, geometric bounds:{myCurrentVertical + 2, myCurrentHorizontal, myCurrentVertical + myBarOrSpaceheight + 2, myCurrentHorizontal + (myBarOrSpaceWidth * thisBarOrSpace)}}
select myBar existing selection add to
end if
set myCurrentHorizontal to myCurrentHorizontal + (myBarOrSpaceWidth * thisBarOrSpace)
set i to i + 1
end repeat
end tell
end tell
end doChecksum
|
export pdf or jpg |
Script that will export a pdf or a JPG from an InDesign File. Choose the file using the dialog. It checks that it is the right type. set the parameter to 'jpg' or 'pdf'. Note that if you select a non-InD file you will get feedback. |
tell current record
set myFormat to (repetition 1 of cell "WOR420::parameters")
end tell
tell application "Finder"
set dsktp to desktop as text
set myFile to (choose file)
if file type of myFile is "IDd4" then
open file myFile
set myName to name of myFile
else
display dialog "Hey Bud!" & return & "This ain't no InDesign file, so I ain't touchin' it!" buttons {"OK"}
return
end if
end tell
tell (a reference to my text item delimiters)
set {oldDelim, contents} to {contents, "."}
set {myName, contents} to {(first text item of myName), oldDelim}
end tell
tell application "Adobe InDesign CS2"
--note that we don't need to 'tell document 1'
--since we are specifying it in the commands
if myFormat is "pdf" then
set view PDF of PDF export preferences to false
set tempDocRef to (dsktp & myName & ".pdf")
export document 1 format PDF type to tempDocRef
else
set JPEG Quality of JPEG export preferences to maximum
set tempDocRef to (dsktp & myName & ".jpg")
export document 1 format JPG to tempDocRef without showing options
end if
close document 1 saving no
end tell
|
Get and set swatches |
The first part of this collects color swatches from an open document and stores them in a list. The second part creates an new document and adds any that aren't in the new document |
global myItemList
global myList
tell application "Adobe InDesign CS2"
set myItemList to {}
--first part
tell document 1
--we expect there to be an open document
-- to get the colours from
set myList to properties of every swatch
copy {"Swatches"} to end of myItemList
copy myList to end of last item of myItemList
end tell
--second part
--make a new document to add the colours to
set tempdoc to make new document
zoom layout window 1 given fit page
tell tempdoc
activate
repeat with thisItem in myItemList
if (item 1 of thisItem) as text is "Swatches" then
repeat with thisSwatch in item 2 of item 1 of myItemList
if not (exists swatch (name of thisSwatch)) then --if it’Äôs already there it’Äôll give an error
if exists (color value of thisSwatch) then
make new color with properties {model:spot, color value:(color value of thisSwatch) as list, space:CMYK, name:name of thisSwatch}
end if
end if
end repeat
end if
end repeat
end tell
end tell
|