Article View: adobe.scripting.indesign
Article #8156Re: [AS CS] get link name (only characters before certain delimiter)
From: plain*clothes
Date: Wed, 01 Nov 2006 20:05
Date: Wed, 01 Nov 2006 20:05
53 lines
2419 bytes
2419 bytes
that did the trick! I knew it was an easy fix, I just couldn't remember where I'd read about the solution. here's the script, for those who came to beg, borrow, or steal.
(*
written, tested, and completely un-guaranteed
by David Holman (david*at*plain-clothes*dot*com)
* )
tell application "InDesign CS"
--activate
set the clipboard to nothing
set origDelim to AppleScript's text item delimiters
set myDoc to active document
tell myDoc
--warn if no selection or incorrect selection exists
if selection exists then
if class of selection is in {graphic, polygon, rectangle, image} then
--get the file name of the linked image
if class of selection is in {polygon, rectangle} then
set fileName to (name of item link of all graphics of item 1 of selection) as string
else
set fileName to (name of item link of item 1 of selection) as string
end if
--extract the trans number from the file name
try
set AppleScript's text item delimiters to {"."}
set noExt to first text item of fileName
set AppleScript's text item delimiters to {"_"}
set transNum to first text item of noExt
--copy trans number to clipboard
set the clipboard to transNum
on error
set AppleScript's text item delimiters to origDelim
display dialog "the script failed to extract the desired portion of the file name." buttons {"damn."} default button 1
end try
set AppleScript's text item delimiters to origDelim
beep
else
display dialog "Please select an image and retry." buttons {"oops!"} default button 1
end if
else
display dialog "Please select an image and retry." buttons {"oops!"} default button 1
end if
end tell
end tell
Technical Details
Message-ID:
<3bc225da.1@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!news.ecp.fr!news.albasani.net!news.isoc.lu!webcrossingReferences:
<3bc225da.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,e73472ff44a63b1c X-Google-Attributes: gidf939a,public X-Google-Language: ENGLISH,ASCII-7-bit From: plain*clothes@adobeforums.com Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!news.ecp.fr!news.albasani.net!news.isoc.lu!webcrossing Newsgroups: adobe.scripting.indesign Subject: Re: [AS CS] get link name (only characters before certain delimiter) Message-ID: <3bc225da.1@webcrossing.la2eafNXanI> Date: Wed, 1 Nov 2006 12:05:31 -0800 References: <3bc225da.-1@webcrossing.la2eafNXanI> Lines: 61 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit