I'm trying to set up an Indesign script that copies the link information of a selected image and appends it to a text file to the desktop, if the text file does not exist it creates one. The link information is copied to the clipboard using a custom key command in inDesign. The problem is if I copy some text or an image beforehand, that text remains on the clipboard. Even though I copy new link info and set that clipboard to a variable.
I know this is an ugly script, I'm just good enough to get by, but barely. Any suggestions on how to clear out the clipboard?
Thanks, ~David
--dialog box
display dialog "What do you need done" default answer "Remove Background"
set theAnswer to (text returned of result)
set this_story to "
------------------- " & theAnswer & " -------------------
"
set this_file to (((path to desktop folder) as string) & "Corrections.txt")
my write_to_file(this_story, this_file, false)
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is true then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
--copy link information using keyboard short
activate application "Adobe InDesign CC 2015"
tell application "System Events" to keystroke "l" using {shift down, control down}
end
---
set myVar to the clipboard
my write_clip_file(myVar, this_file, false)
on write_clip_file(myVar, target_file, append_data)
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is true then set eof of the open_target_file to 0
write myVar to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_clip_file