AppleScript to import .ris files

I’m trying to import a large number of .ris files and I want to do it via AppleScript, but I’m having no luck doing so.  Can anyone please help?  Thanks

[code]

property extension_list : {“ris”}

on adding folder items to this_folder after receiving these_items

set endnoteFile to":Users:me:Documents:MyLib.enlp"

 – PROCESS EACH OF THE ITEMS ADDED TO THE ATTACHED FOLDER

try

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

 – CHECK TO SEE IF THE ITEM IS AN IMAGE FILE OF THE ACCEPTED FILE TYPE

if (alias of the item_info is false and the name extension of the item_info is in the extension_list) then

tell application “EndNote X3”

  activate

  set myDB to open endnoteFile

  import this_item into myDB

  close myDB saving yes

end tell

tell application “Finder”

  activate

  move this_item to trash

end tell

end if

end repeat

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 adding folder items to

[/code]

Daniel

Here is a script I have to simulate a direct export when a file is added to a folder:

set pathToEndNote to POSIX path of “/Applications/EndNote X3/EndNote X3.app”

on adding folder items to this_folder after receiving these_items
    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” then
            try
                do shell script “open -a “” & pathToEndNote & “” “” & this_item & “””
            end try
        end if
    end repeat
end adding folder items to

>Here is a script I have to simulate a direct export when a file is added to a folder:

I think I’m missing understanding something.  The script you posted exports files?  I’m trying to import .ris files I’ve downloaded from pubs.acs.org

Either way I tried your script as was posted, and nothing happened.  So I redid it a bit, and added error messages.  Also, a SET won’t be defined if it’s above a TRY or a an ON.  You’ll need to use properties or move the set.  


on adding folder items to this_folder after receiving these_items

set pathToEndNote to POSIX path of"/Applications/EndNote X3/EndNote X3.app"

try

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” then

do shell script"open -a “” & pathToEndNote & “” “” & this_item & “”"

tell application “Finder”

  activate

  move this_item to trash

end tell

end if

end repeat

  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 adding folder items to


Here’s what happened:

Error:

dyld: shared cached file was build against a different libSystem.dylib, ignoring cache

dyld: shared cached file was build against a different libSystem.dylib, ignoring cache

The file /PATH:Path:path:file.ris does not exist.

Daniel

I ended up posting an older version of the script, when I went in to configure the folder actions and edited the script from there it brought up a different version of the script. There are two differences in this new script. First, it will use the latest version of EndNote that is installed, no need to hard code it. Second, the path to the file when passed to EndNote is sent as POSIX.

Direct Export is the process used, typically when downloading references from a website, that has the references exported directly from the website into EndNote. This is import references into EndNote without you needing to go to File > Import. I verified this script for me this morning:

-- 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
	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 & "\""
			end try
		end if
	end repeat
end adding folder items to

That’s seriously awesome; it worked like a charm.  Thanks Peter, this is going to save me so much time!

Daniel

Another related question.  When this script activates, a dialog box pops up in EndNote asking me to select a reference library.  Since I only ever use 1 library (99% of the time), is there a script command to simply import the ref into the currently active library?

Daniel

The first time references are imported into that library during the session you will be prompted to select a library.  But if you leave EndNote running with that library open you should not be prompted on other imports.

*Edit

After testing this more it appears that the prompting to select a library may or may not appear based on actions performed in the library after the last import.  I currently do not have a script to get around the prompting to select a library.

>The first time references are imported into that library during the session you will be prompted to select a library.  But if you leave EndNote running with that library open you should not be prompted on other imports.

It’s prompting me for every import, even in the same session.