Bibliographic/Hints and Tips/Import Macros
From Apache OpenOffice Wiki
Introduction
Add these OOo basic macro. Using
Tools->Macros->Organize Macros->'OpenOffice basic ..."
The macros calls the file picker dialog and uses the selected *.ris or *.bib file as input to the import_ris or import_bib batch scripts. The import_bib script uses bibutiles programs to convert BibTeX to xml to RIS.
Import RIS bibliographic data
Sub ImportRIS Dim oFilePicker As Object, oSimpleFileAccess As Object Dim oSettings As Object, oPathSettings As Object Dim oTextField As Object, oTextFieldModel As Object Dim sFileURL As String Dim sFiles As Variant REM file dialog oFilePicker = CreateUnoService( "com.sun.star.ui.dialogs.FilePicker" ) REM set filter oFilePicker.AppendFilter( "ris files (*.ris)", "*.ris" ) oFilePicker.AppendFilter( "All files (*.*)", "*.*" ) oFilePicker.SetCurrentFilter( "ris files (*.ris)", "*.ris" ) REM if no file URL is set, get path settings from configuration REM set display directory oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" ) If oSimpleFileAccess.exists( sFileURL ) And oSimpleFileAccess.isFolder( sFileURL ) Then oFilePicker.setDisplayDirectory( sFileURL ) End If REM execute file dialog If oFilePicker.execute() Then sFiles = oFilePicker.getFiles() sFileURL = sFiles(0) rem print sFileURL Shell("import-ris",1,sel) End If End Sub
Note: You may need to add the full path to the import-ris script file in the Shell command, if it produces a can not find error message.
Import BibTeX bibliographic data
Sub ImportBibTeX Dim oFilePicker As Object, oSimpleFileAccess As Object Dim oSettings As Object, oPathSettings As Object Dim oTextField As Object, oTextFieldModel As Object Dim sFileURL As String Dim sFiles As Variant REM file dialog oFilePicker = CreateUnoService( "com.sun.star.ui.dialogs.FilePicker" ) REM set filter oFilePicker.AppendFilter( "BibTeX files (*.bib)", "*.bib" ) oFilePicker.AppendFilter( "All files (*.*)", "*.*" ) oFilePicker.SetCurrentFilter( "BibTeX files (*.bib)", "*.bib" ) REM if no file URL is set, get path settings from configuration REM set display directory oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" ) If oSimpleFileAccess.exists( sFileURL ) And oSimpleFileAccess.isFolder( sFileURL ) Then oFilePicker.setDisplayDirectory( sFileURL ) End If REM execute file dialog If oFilePicker.execute() Then sFiles = oFilePicker.getFiles() sFileURL = sFiles(0) rem print sFileURL Shell("/opt/openoffice.org2.0/program/import_bib",1,sel) End If End Sub
Improvements needed
It would be good if the macros collected the sysout from the utility programs and displayed them to the user so that she may see any error messages.
Add to Menu
One you have saved these macro you can assign it to a new menu item or hot-key in the Tools->customize options. screen pic David Wilson