This is my first Applescript and it runs flawlessly on my development Mac and on another G4 box here. But when I send it on to the client they get Applescript runtime errors and other issues. How is it a script can run correcly on one machine and not on another? The script was develped using Script Debugger 4, and uses one Add-on script. I provided very explicit instructions on how to install the script and the extra (TextCommands) addon.
I’m posting the script to see if anybody can point out any thing that would be machine dependant or cause the script to fail on certain machine configs.
TIA!
=Alan R.
--This script to create a Slug area and add text in that area to indicate:
--File Name
--Created on Timestamp
--Modfied on Timestamp
--As file is modified, the Name will always refelect the current name, the Created on
-- Timstamp is only created once, on first run, and if the document is modified, the
-- Modified on is changed to the current time. The document is saved on every run
set slugTop to 0.4
set tsTop to slugTop * -1 --Neg offset into slug area for text frame
tell application "Adobe InDesign CS2"
set myDoc to active document
tell myDoc
if modified then -- Only do something if the current doc is modified
try
set tsStyle to make new character style with properties {name:"TStxt", point size:6, applied font:"Helvetica"}
end try
set docNam to name
try
set ts to contents of text frame 1
ts contains "Created On:"
set tsframe to text frame 1
tell tsframe
tell application "TextCommands"
set tmp to text of tsframe
set crOn to item 2 of (split tmp using return splitting first 2)
end tell
--set crOn to second paragraph of contents
set ts to "File: " & docNam & return & crOn & return & "Modified on: " & (current date)
end tell
on error
-- Come here for first-time execution and make "Created" info
tell document preferences
set slug top offset to slugTop
end tell
set tsframe to make text frame
set applied character style of first insertion point of tsframe to tsStyle
tell tsframe
set geometric bounds to {0, 0.2, tsTop, 4} -- top,left,bott,right
set contents to " "
-- put fill-text in so fonts will take
end tell
set ts to "File: " & docNam & return & "Created on: " & (current date)
--set applied character style of every character to tsStyle
end try
set text of tsframe to ts as string
--set applied character style of every character of tsframe to tsStyle
else
display dialog "Document not modified - Timestamp not updated"
end if
save
end tell
end tell
1> Where is it bombing out at? Whats the error the receive?
2> Are you 100% positive they have installed the scripting addition and program properly?
3> Are you positive they have CS 2?
Side Comment
1> I would get in the happen of building logging into your scripts especially if they are not for your own in house projects. Things are much easier to troubleshoot when a client can send you a log file containing information on exactly what is going wrong.
2> If #2 above is a possibility you could always make a package installer that insalls the sa and program to their proper location.
There could be problems with AppleScript versions, OS versions, and InDesign versions. I have been in discussions with others in the forms that have had problems with scripts running on one computer and not another, some were solved by installing an InDesign update. Another possible problem might be the script on the new computer might not know how to find the TextCommands application, recompiling it on the new system might solve the problem.
There were two errors - one was a -2753 “tsStyle” not defined. Think the other was -10000. If they had no font that corresponded to “Helvetica” it would break - but isn’t that a std OS X system font?
The client does have CS2 but another tester used CS. Given the simplicity of the script it would seem it should be “version-agnostic” – no?
AFAIK the scripts are in right. TextCommands can be pretty much anywhere on the machine, and the InDesign script has to be in the right place (in the ID folder) or it wouldn’t be available to test. And that is it. Are there any core scripts I could have installed that might be missing on another system?
Being the AS noob I am, I’m not familiar with using logging as you suggest. How would I get the client’s log? Is a file created?
I ran your script on my computer at home, an aging 450 G4 Cube with 10.3.9 and InDesign CS, and after changing a few things in my document it worked OK, but then again it was recompiled on my computer so all the “aliases” to the programs were resolved.
I would change your script to check the measurement system that the document is using and change it if neccessary so that the text box is built the proper size and in the proper place. You should not assume that each document that each user opens is going to be set to use the same units. In my experience there are a lot of people that use inches, but there are just as many that use picas here in the US and some people change them as needed while they are working. I use points, picas, and inches depending on what I am doing. When I script I always set up my scripts to work in points and change the document properties to points units (as well as reset the zero point, and ruler settings) while it is running and back when it is done.
For the font I would not use Helvetica, there are a number of different Helveticas out there, and you might not get what you were going for, and it is not a neccessary font for OS X and a lot of people in the design field probably remove it from the system fonts so that they can control which version they are using (TT, T1, OT). This is probably why your scirpt is not setting up the character style, and since it is in a try block no error is being returned when it cannot set up the style. I would use a font that HAS to be in the system (Chicago, Geneva come to mind), or tell your clients that a specific font needs to be loaded to run the script.
I don’t think that the problems that you are having are becouse something is not installed, but then I would check to make sure that the versions of InDesign are the same, or test it on the different versions. I have talked to other people who have had problems with a script woking on one verson on one machine, but not working on an updated version on another machine. I wouldn’t be suprised at all if an update “Broke” a script either, I know Adobe changed the way some script commands and properties work between ID 2, ID CS, and ID CS2.
I’ve added a function to read the document units and measure prefs and return a multiplier which I use with the reference postions set as inches. From that comes the geometric offset of the text frame. It can even handle different horiz and vertical units. Also improved the TRY for the character style. Set font to be Geneva. Works (as before) like a charm here - now awaiting comments from the field.