How to select a file in an "Open Item" dialog box
1) If a .ris file gets added to the Downloads folder
2) Open that file with EndNote
3) and import that file into the currently active library
4) jump back to the application that was active before the script started doing stuff
5) move the newly imported .ris file to the trash
The problem is, that EndNote keeps asking me to select the library into which I wish to import. I've asked about this on the EndNote forums and there is no solution. The main body of the script was taken from a post there. Here's the section of the script I'm having trouble with is making it select "HydrideLibrary.enlp" when the window "Select a Reference Library" pops up. Please help!
--section to wait for window to pop up
repeat until temp = 1
tell application "EndNote X3"
if (name of front window contains "Select a Reference Library") then
set x to 1
end if
end tell
end repeat
delay 0.5
--section to select HydrideLibrary.enlp
tell application "System Events"
tell process "EndNote X3"
select item "HydrideLibrary.enlp" of table 1 of scroll area 2 of group 1 of tab group 1 of window "Select a Reference Library"
delay 1
keystroke return
end tell
end tell
The full script is below:
-- Direct Export.scpt
-- Thomson Reuters 2009
--
-- Installing:
-- 1) Copy this script to your ~/Library/Scripts/Folder Action Scripts
-- 2) Run the application /Applications/AppleScript/Folder Actions Setup
-- 3) Click on the + in the lower left corner
-- 4) Select the Downloads folder in your Home folder
-- 5) You will then be prompted to select the script, select "Direct Export.scpt" and click on Attach
-- Now when performing a direct export and the file is saved in Downloads, EndNote will will perform an import using that file if it's extension is ris, enw, or ovd
on adding folder items to this_folder after receiving these_items
if (count of these_items) is equal to 0 then
quit
else
set front_app to (path to frontmost application as Unicode text)
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to the info for this_item
set file_extension to the name extension of item_info
if file_extension = "enw" or file_extension = "ris" or file_extension = "ovd" or file_extension = "cgi" then
-- Locate the newest version of EndNote. This is located here to prevent this code being run every time a file is downloaded.
-- You could hard code the app by changing the line:
-- set ENApp to ""
-- to
set ENApp to POSIX path of "/Applications/EndNote X3/EndNote X3.app"
--set ENApp to ""
--set n to 9
--set bExists to false
--repeat while n > 0 and ENApp = ""
--set pathToTest to "/Applications/EndNote X" & n & "/EndNote X" & n & ".app"
--check to see if the App exists
--tell application "Finder" to if exists pathToTest as POSIX file then set bExists to true
--if bExists is true then
--set ENApp to POSIX path of pathToTest
--end if
--set n to n - 1
--end repeat
-- if we were unable to locate a copy of EndNote exit
--if ENApp = "" then
--return
--end if
-- open the file with EndNote
set fileToOpen to POSIX path of this_item
try
do shell script "open -a \"" & ENApp & "\" \"" & fileToOpen & "\""
set temp to 0
repeat until temp = 1
tell application "EndNote X3"
if (name of front window contains "Select a Reference Library") then
set x to 1
end if
end tell
end repeat
delay 0.5
tell application "System Events"
tell process "EndNote X3"
select item "HydrideLibrary.enlp" of table 1 of scroll area 2 of group 1 of tab group 1 of window "Select a Reference Library"
delay 1
keystroke return
end tell
end tell
delay 1
tell application "Finder" to move this_item to trash
tell application front_app to activate
tell application "Safari" to close window named "Downloads"
on error error_message number error_number
if the error_number is not -128 then
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
end tell
end if
end try
end if
end repeat
end if
end adding folder items to
MacBook, Mac OS X (10.5.6)