At one point in the script the user is prompted with SystemUIServer dialog box. For example:
set theValue to text returned of (display dialog “Enter Value” default answer “???”)
Sometimes the user will copy text from InDesign. But when they go to paste it does not appear in the dialog box. (not sure why?)
Therefore I want to detect if “Command and V” were pressed by the user. But I don’t want to use System Events to automatically do the paste because very often the user will type a specific word.
My question is this: Is there a way to deter determine if the keystrokes “Command and V” are pressed at the time the user is presented with the dialog box? If I could determine this then I can pass the clipboard text (at least I think I could?) using a variable such as this.
set myClipboard to the clipboard as string
Any other keystroke should just equal the values passed to the dialog box. I searched pretty extensively for this but could not find this?
Why not just have buttons {“Cancel”, “It’s on the Clipboard”, “Enter”}?
EDIT: Like so:
set {tButton, tAnswer} to {button returned, text returned} of (display dialog "something" default answer "????" buttons {"Cancel", "It's on the Clipboard", "Enter"})
if tButton contains "Clipboard" then set tAnswer to the clipboard
On second thought, I do think operators are going to want to see the actual text prior to clicking return.
Maybe I need to approach this in a different way? For example, I can paste from InDesign to an intermediate application, such as Text Edit. Then I could copy and paste that information from Text Edit into the UI field in the dialog box and it will display the text in the field. But that is slow. Maybe there is a way to convert the copied string to something like unicode text that may be accepted in the UI?
I kind of need to picky about this because the script itself takes awhile to run. It would be burdensome for them to realize they pasted an extra character after the fact.
set {tButton, tAnswer} to {button returned, text returned} of (display dialog "something" default answer "????" buttons {"Cancel", "It's on the Clipboard", "Enter"})
if tButton contains "Clipboard" then
display dialog (the clipboard) buttons {"Cancel", "It's OK"}
set tAnswer to the clipboard
-- press on
else
display dialog "You entered " & return & return & tAnswer buttons {"Cancel", "It's OK"}
-- press on
end if
You might want to check to see if the clipboard is text; the user might have a big jpeg there. There’s a “clipboard info” that will tell you the type of stuff in the cb.
I know this may seem crude and taboo in terms of scripting, but this workaround seems to work.
FWIW, I am only seeking to past single date string, i.e., 10/30/07 from an InDesign document. I figured I could paste it somewhere else, copy it again, and then the Applescript’s dialog box will display the characters in the field upon “Cmd-V”.
I can achieve this in a rather unobtrusive way be copying the text from InDesign to a new folder, then copy the folder’s name, then dump the folder. At that point the clipboard’s text data will be visible, when the operator using “Cmd-V”. This all happens relatively fast but maybe there is a better way?
(* This will copy the clipboard info to a folder on the desktop *)
--set cbContent to (the clipboard)
set cbClass to class of (the clipboard)
--if ((cbClass is picture) or ((cbClass is record) and (picture of cbContent))) then
--display dialog cbClass
if cbClass is Unicode text then
try
tell application "Finder"
activate
select window of desktop
tell application "System Events"
keystroke "n" using {command down, shift down}
delay 0.1
keystroke "v" using command down
keystroke "a" using command down
keystroke "c" using command down
keystroke "z"
keystroke (ASCII character 3)
end tell
end tell
end try
end if
delay 0.1
try
set FolderToDelete to (path to desktop as Unicode text) & "z"
do shell script "rm -r " & quoted form of POSIX path of FolderToDelete
on error
delay 0.1
try
set FolderToDelete to (path to desktop as Unicode text) & "z"
do shell script "rm -r " & quoted form of POSIX path of FolderToDelete
end try
end try
tell application "Adobe InDesign CS2"
activate
end tell
Slightly different way of seeing what is in the clipboard , Text or image
this shows you the actual clipboard
set {tButton, tAnswer} to {button returned, text returned} of (display dialog "something" default answer "????" buttons {"Cancel", "It's on the Clipboard", "Enter"})
if tButton contains "Clipboard" then
tell application "Finder"
activate
try
tell application "System Events"
click menu item "Show Clipboard" of menu 1 of menu bar item "Edit" of menu bar 1 of application process "Finder"
end tell
display dialog "Check the clipboard wndow" buttons {"Cancel", "It's OK"}
set tAnswer to the clipboard
close window "Clipboard"
on error
close window "Clipboard"
end try
end tell
-- press on
else
display dialog "You entered " & return & return & tAnswer buttons {"Cancel", "It's OK"}
-- press on
end if