Copy link to clipboard
Copied
hi,
i've got a challange, can somebody please help me?
I'm a graphic designer from holland and I work with lots of Indesign documents
whose links are missing because they are moved, so they are somewhere on our server.
I have several scripts to relink missing links but they are slow,
because they search every directory and every subdirectory. This takes a while.
The search engine from apple, spotlight, is much much faster.
So I think i have this brilliant idea, i thought of the following:
I select one missing link in the linkpanel in Indesign.
Then I start the script.
The path of the missing link is copied and trimmed to just the name of the file
The filename is then copied to the clipboard.
The script then opens the dialog window to relink the missing link.
There the name of the picture is pasted in the spotlight search engine.
There the script stops.
Click on the correct file (if there are more choises) and the relink is made.
I think this way of relinking can be much faster.
And you can also work with pre-defined clever windows (to limit the results), for example:
- one witch only shows jpg
- one witch only shows tiff
- one witch only shows pdf
I know a tiny little bit of scripting, but this one I cant figure out yet.
Can somebody give me a help please?
Kind regards, Eric
ps. I still work in CS4
Fine that you've got a solution and sorry for quitting yout ID. Should have tested it more then once, it's been a quite old script and I just copy and pasted it ...
just rewrote my old script a bit to run on ID CS 5.5 OSX 10.7.4
Should run over missing links of active Document, uses mdfind to find files with simular names as missing link name in the given directory, optionally reveals the file in finder and shows / selects currMissingLink in ID-file. if "ok" relinks the missing link (without qu
...Copy link to clipboard
Copied
If you want spotlight searching in script… You should do man mdfind in the terminal app… This will show you the scriptable options for the command… You would need to call the shell from AppleScript. Your subject would probably be better answered at…
http://macscripter.net/viewforum.php?id=2
Where more forum users are familiar with both AppleScript and shell… Not sure you will achive the kind of user interaction you envisage and be fast… Drop the clipboard idea it's not needed… Just a bit of text…
Copy link to clipboard
Copied
Muppet Mark,
Thank you very much for your reply but i don't think that you quite understand my request.
I don't want to use spotlight in a script. I want to make use from spotlight whitch is already build in in the standard dialog window from InDesign, the window whitch appears when you click: 'relink the image'.
All the script has to do is copy te name of the missing link and then paste the name of the image in that dialog in the right upper corner, the spotlight search.
That's all.
Copy link to clipboard
Copied
try this,
could just test it with ID CS3 and Mac OS 10.4.11
--startpoint here is a selected graphicframe (which of course should inlude the missing link)
set myFolder to choose folder with prompt "Where to search for the missing link?" --select a mounted volume, folder ...
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
tell application "Adobe InDesign CS3"
set myGraphicFilePath to (file path of (item link of (item 1 of all graphics of (item 1 of selection))) as text)
end tell
set myGraphicName to text item -1 of myGraphicFilePath
set myGraphicFilePath to quoted form of POSIX path of myGraphicFilePath
set AppleScript's text item delimiters to return
set PathToAllFiles to every text item of (do shell script "mdfind -onlyin '" & quoted form of POSIX path of myFolder & "'" & space & " -name '" & myGraphicName & "'")
set PathToAllFiles to my cleanList(myGraphicName, PathToAllFiles)
repeat with i from 1 to count of PathToAllFiles
set theItem to (item i of PathToAllFiles)
if button returned of (display dialog theItem with title "Relink this file?" buttons {"OK", "Cancel", "Go on"}) is "OK" then
tell application "Adobe InDesign CS3"
relink (item link of (item 1 of all graphics of (item 1 of selection))) to POSIX file theItem
end tell
end if
end repeat
set AppleScript's text item delimiters to tid
on cleanList(fileName, listOfFilePaths)
set myCleanList to {}
set AppleScript's text item delimiters to "/"
repeat with p from 1 to count of listOfFilePaths
set aName to (text item -1 of (item p of listOfFilePaths))
if aName is equal to fileName then set end of myCleanList to (item p of listOfFilePaths)
end repeat
return myCleanList
end cleanList
Hans-Gerd Classen
Copy link to clipboard
Copied
Thank you guys for your response,
the last script was interesting, but it made my indesign to quit, 2 times in a row. Don't know why.
(yes I changed CS3 to CS4)
After some thinking, I came up with the following solution:
Set in the prefs, the keyshortcuts from InDesing these keystrokes:
- ga naar koppeling "shift §" - (english: go to link?)
- opnieuw koppelen "commando §" - (english: re-link?)
- volledig pad kopiëren "§" - (english: copy path of link?)
After this, this is the script I run:
activate application "Adobe InDesign CS4"
tell application "System Events"
keystroke "§" using shift down
keystroke "§"
end tell
delay 0.5
set LinkPath to do shell script "pbpaste"
set AppleScript's text item delimiters to {"/"}
set delimitedList to last text item of LinkPath
set the clipboard to delimitedList
tell application "System Events"
keystroke "§" using command down
keystroke "f" using command down
keystroke "v" using command down
keystroke "2" using command down
end tell
This works for me! 🙂
Copy link to clipboard
Copied
Fine that you've got a solution and sorry for quitting yout ID. Should have tested it more then once, it's been a quite old script and I just copy and pasted it ...
just rewrote my old script a bit to run on ID CS 5.5 OSX 10.7.4
Should run over missing links of active Document, uses mdfind to find files with simular names as missing link name in the given directory, optionally reveals the file in finder and shows / selects currMissingLink in ID-file. if "ok" relinks the missing link (without quitting ID 😉 I hope).
global myFolder
set tid to AppleScript's text item delimiters
tell application "Adobe InDesign CS5.5"
set currDoc to active document
set theMissingLinks to every link of currDoc whose status is link missing
if theMissingLinks is not {} then set myFolder to choose folder with prompt "Where to search for the missing links?" --select a mounted volume, folder ...
repeat with missingLink from 1 to count of theMissingLinks
set currMissingLink to item missingLink of theMissingLinks
set currFileName to name of currMissingLink
set theResultList to my mdFind(currFileName)
if theResultList is not {} then
repeat with i from 1 to count of theResultList
set theItem to (item i of theResultList)
set currDialog to display dialog theItem with title "Relink this file?" buttons {"OK", "Cancel", "Show in Finder first"}
if button returned of currDialog is "OK" then
try
relink currMissingLink to POSIX file theItem
on error e
display dialog e
end try
else if button returned of currDialog is "Show in Finder first" then
show currMissingLink --select the missing link in ID
my revealInFinder(theItem) --show the found file in finder
activate
set currDialog to display dialog theItem with title "Please switch to Finder to see the file. Relink the file shown in Finderwindow?" buttons {"OK", "Cancel", "Continue searching"}
if button returned of currDialog is "OK" then
try
relink currMissingLink to POSIX file theItem
on error e
display dialog e
end try
end if
end if
end repeat
end if
end repeat
end tell
on mdFind(currFileName)
set AppleScript's text item delimiters to return
set PathToAllFiles to every text item of (do shell script "mdfind -onlyin '" & quoted form of POSIX path of myFolder & "'" & space & " -name '" & currFileName & "'")
set PathToAllFiles to my cleanList(currFileName, PathToAllFiles)
end mdFind
set AppleScript's text item delimiters to tid
on cleanList(fileName, listOfFilePaths)
set myCleanList to {}
set AppleScript's text item delimiters to "/"
repeat with p from 1 to count of listOfFilePaths
set aName to (text item -1 of (item p of listOfFilePaths))
if aName is equal to fileName then set end of myCleanList to (item p of listOfFilePaths)
end repeat
return myCleanList
end cleanList
on revealInFinder(somePosixPath)
tell application "Finder"
set myAlias to (POSIX file somePosixPath) as alias
activate
reveal myAlias
end tell
end revealInFinder
Hope it'll run
Hans-Gerd Claßen
Copy link to clipboard
Copied
Thanx for your reply and the trouble you went thru of rewriting the script.
Just tested it twice and it works like a charm!
Thought I ought to let you know...
Thanx again
Copy link to clipboard
Copied
thx & tot ziens 😉
Copy link to clipboard
Copied
"Thought I ought to let you know..." You can do that by making the subject answered… and giving the deserved points… were all after a free mug…
Copy link to clipboard
Copied
Hi,
no problem, i have to do that tomorrow, from my work.
For some reason, when I log in at home with the same login information, it uses my first attempt account.
Look at the name, from my work its 'Lipton Ice' and from at home its 'Ice Lipton'.
I'll try tommorow, see if i can find it, i'm kinda new here..., ok?
Grtz, Eric
Copy link to clipboard
Copied
Whenever I try to run this script I get the following error:
error "Unknown option -
Usage: mdfind [-live] [-count] [-onlyin directory] [-name fileName | -s smartFolderName | query]
list the files matching the query
query can be an expression or a sequence of words
-live Query should stay active
-count Query only reports matching items count
-onlyin <dir> Search only within given directory
-name <name> Search on file name only
-s <name> Show contents of smart folder <name>
-0 Use NUL (``\\0'') as a path separator, for use with xargs -0.
example: mdfind image
example: mdfind -onlyin ~ image
example: mdfind -name stdlib.h
example: mdfind \"kMDItemAuthor == '*MyFavoriteAuthor*'\"
example: mdfind -live MyFavoriteAuthor
" number 1
I've pasted your full code into the Applescript editor and I'm trying it to run in InDesign CS5.5
I've tried modifying the script here and there, but can't seem to get it to work. (I have not made myself familiar yet with running shellscripts within Applescript.)
Any chance you could help me with this?
Copy link to clipboard
Copied
Hi,
it's been built for lion, ID 5.5. Mdfind-command seems to be ok. perhaps it's a copy paste problem. try the link https://dl.dropboxusercontent.com/u/11350320/mdFind_Relink.scpt.zip
Copy link to clipboard
Copied
Hi Hans,
thanks for the quick reply.
I'm still getting the same error. I am working on Mountain Lion (10.8.4), so maybe that's why I get the error?
--edit
It seems that I only get the error when I point the script the certain folders.
The folders that give the error are indexed by spotlight, but still give the error.
I'll try to rebuild my spotlight index and see if that will work.
Copy link to clipboard
Copied
This would be fantastic if it would work. Any news?
Copy link to clipboard
Copied
Working in a graphic design studio I had the same problem. We often supply collected files to other designers who return the Indesign documents updated for us to use but the images are still linked to the collected folder. This is what prompted me to write this AppleScript so that I could relink them back to our master images libraries.
Indesign Image Relinker – Dr Scripto
The script asks you to point it to the top level of a directory and it searches every subdirectory within it for the images. You can ask it to relink selected images, missing images or all images to the chosen directory. The script uses a shell script to create an index of the directory structure which is super quick and it then searches every subfolder for the links and relinks them to the document.