Article View: adobe.scripting.indesign
Article #18064First AppleScript (AS) [large script in body]
From: Chris Haas
Date: Mon, 28 Apr 2003 06:29
Date: Mon, 28 Apr 2003 06:29
91 lines
4103 bytes
4103 bytes
I've been a Basic programmer for 12+ years now and have many VB scripts for
ID but this is my first AppleScript. I was wondering if someone could take a
look at this script which relinks all images from LoRes to HiRes and tell me
how bad it is. I just learned AS this weekend and I can't find the VB
equivalent of Replace so I just made one. I think I could ask the finder to
tell me the Volume name instead of manually parsing it but I'm a function
guy. Please, any comments would greatly be appreciated, both in my
AppleScript mistakes and my InDesign mistakes. The script seems to work
beautifully, btw.
Thanks!
[BEGIN]
set MY_OLD_VOLUME to "FPO"
set MY_NEW_VOLUME to "HighRes"
set lstAlreadyLinked to {""}
set lstUnknownServer to {""}
set SHOW_ERRORS to true
set show_unknown_servers to true
set SHOW_ALREADY_LINKED to false
tell application "InDesign 2.0.2"
activate
set myID to active document
tell myID
set myLinks to links
repeat with myLink in myLinks
set myOldFilePath to (file path of myLink) as string
ignoring case
if myOldFilePath begins with MY_OLD_VOLUME & ":" then
set myNewFilePath to MY_NEW_VOLUME & ":" & characters
((length of MY_OLD_VOLUME) + 2) thru (length of myOldFilePath) of
myOldFilePath
tell myLink to relink to myNewFilePath
tell myLink to update
else if myOldFilePath begins with MY_NEW_VOLUME & ":" then
set lstAlreadyLinked to lstAlreadyLinked & (name of
myLink)
else
set lstUnknownServer to lstUnknownServer & (my
GetVolumePart(myOldFilePath) & ":...:" & (name of myLink) as string)
end if
end ignoring
end repeat
end tell
end tell
if SHOW_ERRORS then
if SHOW_ALREADY_LINKED then
if length of lstAlreadyLinked > 1 then
set myBackupDelim to text item delimiters
set text item delimiters to return
display dialog "The following items are already linked:" &
(lstAlreadyLinked as string)
set text item delimiters to myBackupDelim
end if
end if
if show_unknown_servers then
if length of lstUnknownServer > 1 then
set myBackupDelim to text item delimiters
set text item delimiters to return
display dialog "I don't know where the following files live:" &
(lstUnknownServer as string)
set text item delimiters to myBackupDelim
end if
end if
end if
on GetVolumePart(someString)
set myRet to someString as string
if someString contains ":" then
set someString to my Replace(someString, ":", return)
ignoring punctuation
set myRet to first paragraph of someString
end ignoring
end if
return myRet
end GetVolumePart
on Replace(StringToSearchIn, StringToSearchFor, StringToReplaceWith)
set myRet to "" as string
repeat with myChar in characters of StringToSearchIn
if (myChar as string) = StringToSearchFor then
set myRet to myRet & StringToReplaceWith
else
set myRet to myRet & myChar
end if
end repeat
return myRet
end Replace
[END]
Technical Details
Message-ID:
<BAD2346B.21A%ChrisH@OvationAdvertising.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.tpinternet.pl!newsfeed01.sul.t-online.de!t-online.de!WebXShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,a14109d39133ad8c,start X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-04-27 23:39:43 PST From: Chris Haas <ChrisH@OvationAdvertising.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.tpinternet.pl!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: First AppleScript (AS) [large script in body] Message-ID: <BAD2346B.21A%ChrisH@OvationAdvertising.com> Date: Sun, 27 Apr 2003 23:29:15 -0700 Lines: 100 User-Agent: Microsoft-Entourage/10.1.0.2006 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit