These are Script fragments that create elements in InDesign and in Quark
|
Text to list |
This takes a delimited text field and converts it into a list. (which FileMaker puts into the repetitions of a repeating field). |
tell current record
set newSep to repetition 1 of cell "parameters"
set myResult to repetition 2 of cell "parameters"
tell (a reference to my text item delimiters)
set {oldDelim, contents} to {contents,newSep }
set {myResult, contents} to {(every text item of myResult) as list, oldDelim}
end tell
end tell
|
List to text |
This takes a couple of lists and converts them into two delimited text fields (using the first repetition of the parameter as a delimiter---and try saying that fast a few times). For convenience of displaying the results we concatenate these into a list (which FileMaker puts into the repetitions of a repeating field). |
tell current record
set newSep to repetition 1 of cell "parameters"
set myResult to {"rat", "cat", "bat", "splat"}
set myOtherResult to {1, 2, 4, 5, 7, 123}
tell (a reference to my text item delimiters) --Later
set {oldDelim, contents} to {contents, newSep }
set {myResult, myOtherResult, contents} to {"" & myResult, "" & myOtherResult, oldDelim}
end tell
set myResult to {myResult, myOtherResult}
end tell
|
Rounding |
Since AppleScript only rounds to an integer, this takes a number and rounds it to the given precision. E.g. 665.666667, -1 -> 670 665.666667, 0 -> 666 665.666667, 4 -> 665.6667 Note it returns a number. |
tell current record
set myNum to repetition 1 of cell "parameters"
set myPlaces to repetition 2 of cell "parameters"
set myResult to my roundMe(myNum, myPlaces)
end tell
on roundMe(myNum, myPlaces)
set myNum to (round (myNum * (10 ^ myPlaces)) rounding as taught in school) / (10 ^ myPlaces)
return myNum
end roundMe
|
Rounding with result as text |
Since AppleScrpt only rounds to an integer, this takes a number and rounds it to the given precision. E.g. 15.1597, -1 -> "20" 1.1597, 0 -> "1" 1.1597, 3 -> "15.160" 1.1597, 6 -> "1.159700" This one is a bit more complicated and returns text formatted correctly. |
tell current record
set myNum to repetition 1 of cell "parameters"
set myPlaces to repetition 2 of cell "parameters"
set myPlaces2 to repetition 3 of cell "parameters"
set myResult to {my roundMe(myNum, myPlaces), my roundMe(myNum, myPlaces2)}
end tell
on roundMe(myNum, myPlaces)
set myNum to (round (myNum * (10 ^ myPlaces)) rounding as taught in school) / (10 ^ myPlaces) as text
tell (a reference to my text item delimiters)
set {oldDelim, contents} to {contents, "."}
set {myNum, contents} to {(every text item of myNum) as list, oldDelim}
end tell
if myPlaces > 1 then
set i to count of (every text item of (item 2 of myNum as text) as list)
repeat while i < myPlaces
set item 2 of myNum to item 2 of myNum & "0"
set i to i + 1
end repeat
tell (a reference to my text item delimiters)
set {oldDelim, contents} to {contents, "."}
set {myNum, contents} to {(every text item of myNum) as text, oldDelim}
end tell
else
set myNum to item 1 of myNum as text
end if
return myNum
end roundMe
|
ASCII conversion |
Usefull for dealing with characters such as AppleScript's escape (\). The first parameter is an integer from 0 to 255 and the second is an ASCII character |
tell current record
set myChar to ASCII character (repetition 1 of cell "parameters" as number)
set myASCII to ASCII number (repetition 2 of cell "parameters" as string)
set myResult to {myChar, myASCII}
end tell
|
Choose from List |
This will return the position of the parameter in the list. If it's not there it returns 0. |
set this_list to {"Sal", "Sue", "Bob", "Slob", "Carl"}
tell current record
set myName to repetition 1 of cell "parameters"
end tell
set myReply to list_position(myName, this_list)
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then return i
end repeat
return 0
end list_position
|
Dialog Choose List |
This opens a dialog from which the user can choose. It returns the values selected. |
set myReply to choose from list {"1", "2", "rhubarb", "3", "4", "Fred", "5", "6", "���"} with prompt "What���s your choice?
Hold down Command for Multiple." with multiple selections allowed -- or [without multiple selections allowed].
|
Sort |
This sorts a list alphabetically using UNIX through a shell script |
tell current record
set theList to cell "parameters"
end tell
set theList to my sortList(theList)
on sortList(theList)
set NL to (ASCII character 10)
tell (a reference to my text item delimiters) -- a more sophisticated way of
set {oldDelim, contents} to {contents, NL} -- dealing with
set {theList, contents} to {"" & theList, oldDelim} -- text item delimiters
end tell
return paragraphs of (do shell script "echo " & (quoted form of theList) & " | sort")
end sortList
|
Curl Upload |
Script returns a directory listing of the site and then uploads anything put into "uploadFolder" and if successful puts them into "filesDone" |
global thisURL
global myDataError
global theFileNameList
global thisResult
tell application "Finder"
set thisURL to "ftp://rhb1:aesc1234@www.howlandbolton.com/howlandbolton.com/"
set thisURL to "ftp://someUser:somePassword@ftp.someSite.com"
set pdfFolderol to ((desktop as text) & "uploadFolder:") --set to Folder of files to upload
set theFileNameList to ""
--this gets a list of what's in the given directory on the site
set strCurl to ("curl -l " & thisURL as string)
set thisResult to (do shell script strCurl)
--turn it into a list
set myOldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set thisResult to (every text item of thisResult)
set AppleScript's text item delimiters to myOldDelim
set thisReturn to (items 1 through 8 of thisResult) --for our returns field
try
set filesList to (files of folder pdfFolderol) as alias list
on error --if there's only one file
set filesList to (first file of folder pdfFolderol) as alias as list
end try
if (count of filesList) > 0 then
repeat with thisFile in filesList
set theName to the name of thisFile
set thisPath to quoted form of POSIX path of thisFile
set strCurl to ("curl -v -T " & thisPath & " " & thisURL as string)
set thisResult to (do shell script strCurl)
if thisResult is "" then --check that it was uploaded
set theFileNameList to theFileNameList & return & theName
move file thisFile to folder ((desktop as text) & "uploadFolder:filesDone:") with replacing
else
set theFileNameList to theFileNameList & return & theName & "NOT COPIED"
set myDataError to myDataError & thisResult
end if
end repeat
end if
end tell
|
Watched Folder |
This is a shell for a watched folder to act on either Quark or InDesign documents either singly or multiple, even in folders |
-- if you drag files or folders onto the watched folder
on adding folder items to thisFolder after receiving theItems
tell application "Finder"
activate
repeat with thisItem in theItems
if last character of (thisItem as text) is ":" then -- it's a folder
set theFiles to (every file of entire contents of thisItem whose (kind is not "alias" and ((file type is "IDd4") or (file type is "XPRJ")))) -- get our sort of files!!!
if the class of theFiles is not list then set theFiles to {theFiles}
repeat with thisFile in theFiles --these are files
set thisType to (the file type of thisFile)
my ProcessThisFile(thisFile, thisType)
end repeat
else
if (the kind of thisItem is not "alias" and ((the file type of thisItem is "IDd4") or (the file type of thisItem is "XPRJ"))) then
--it's our sort of file!!!
set thisType to (the file type of thisItem)
my ProcessThisFile(thisItem, thisType)
end if
end if
end repeat
end tell
end adding folder items to
on ProcessThisFile(thisFile, thisType)
if thisType is "XPRJ" then
tell application "QuarkXPress"
activate
--do quirky stuff
end tell
end if
if thisType is "IDd4" then
tell application "Adobe InDesign CS2"
activate
--do indy stuff
end tell
end if
end ProcessThisFile
|
Droplet |
This is a shell for a droplet to act on documents dragged onto it; either single or multiple docs, even docs in folders are handled. |
--droplet shell
on run -- if you double click on the droplet
display dialog ��
"Drag your Documents onto this icon to process them." buttons {"OK"} default button 1
end run
on open theItems -- if you drag files or folders onto the droplet
tell application "Finder"
activate
repeat with thisItem in theItems
if last character of (thisItem as text) is ":" then -- it's a folder
try
set theFiles to (every file of entire contents of thisItem whose kind is not "alias")
if the class of theFiles is not list then set theFiles to {theFiles}
repeat with thisFile in theFiles --these are files
my ProcessThisFile(thisFile)
end repeat
end try
else
if the kind of thisItem is not "alias" then --it's a file
my ProcessThisFile(thisItem)
end if
end if
end repeat
end tell
end open
on ProcessThisFile(thisFile)
--do something
end ProcessThisFile
|