Skip to content

Instantly share code, notes, and snippets.

@roneyfraga
Created March 6, 2014 02:33
Show Gist options
  • Save roneyfraga/9381135 to your computer and use it in GitHub Desktop.
Save roneyfraga/9381135 to your computer and use it in GitHub Desktop.
-- Roney Fraga Souza
-- 2014-02-03
--
--
-- script para baixar artigos científicos no Web of Science
-- utilizando um arquivo de excel com os códigos DOI
--
-- necessário ter o plugin Vimlike instalado, ele permite
-- encontrar links no navegador
-- necessário ter instalado o ShortCat, software que
-- busca o menu via nome, útil quando a posição dos links
-- mudam e o Vimlike não funciona bem
--
repeat 36 times
-- contar quantos arquivos tem na pasta downloads
tell application "Finder"
set numberOfFiles1 to count of (files in folder "Macintosh SSD:Users:Roney:Downloads")
end tell
-- atribuir o número da primeira contagem de arquivos para a segunda variável
set numberOfFiles2 to numberOfFiles1
-- Excel: seta para baixo e copiar o texto
tell application "Microsoft Excel" to activate
tell application "System Events"
tell process "Excel"
key code 125
keystroke "c" using command down
end tell
end tell
--Safari: abrindo o Web Of Science
tell application "Safari" to set the URL of the front document to "http://apps.webofknowledge.com/WOS_GeneralSearch_input.do?product=WOS&SID=3DcCQ7NBXTjYoRjoEQn&search_mode=GeneralSearch"
--checa status da pagina no safari
tell application "Safari"
activate
delay 1
repeat
-- use Safari's 'do JavaScript' to check a page's status
if (do JavaScript "document.readyState" in front document) is "complete" then exit repeat
delay 2 -- wait a second before checking again
end repeat
end tell
-- Safari: colando o código DOI e enter
tell application "Safari" to activate
tell application "System Events"
keystroke "f"
delay 1
keystroke "as"
delay 2
--keystroke "a" using {command down}
--delay 0.2
keystroke "v" using {command down}
delay 0.2
key code 36
delay 0.2
key code 36
delay 0.2
end tell
--checa status da pagina no safari
tell application "Safari"
activate
delay 5
repeat
-- use Safari's 'do JavaScript' to check a page's status
if (do JavaScript "document.readyState" in front document) is "complete" then exit repeat
delay 1 -- wait a second before checking again
end repeat
delay 1
end tell
--se não existe código DOI, inserir "não encontrado" no excel
--se existe, baixar o arquivo
tell application "Safari"
set urlparateste to URL of front document
if (word 3 of urlparateste = "WOS_GeneralSearch_input.do") then
--tell application "Safari" to activate
--tell application "System Events" to keystroke "w" using command down
tell application "Microsoft Excel" to activate
tell application "System Events"
tell process "Excel"
key code 124 --direita
keystroke "não encontrado"
key code 36 --enter
key code 123 --esquerda
key code 126 --subir
end tell
end tell
else
tell application "System Events"
tell process "Safari"
delay 1
key code 49 using option down
delay 2
keystroke "Save to EndNote online"
delay 3
key code 36
delay 1
key code 125 -- arrow key
delay 1
key code 125
delay 0.2
key code 125
delay 0.2
key code 36 --return
delay 0.2
key code 48
delay 0.2
key code 48
delay 0.2
key code 48
delay 0.2
key code 49 --space
delay 0.2
key code 125
delay 0.2
key code 125
delay 0.2
key code 49 --space
delay 0.2
key code 36
delay 3
end tell
end tell
--esperar o download iniciar
repeat while numberOfFiles1 is equal to numberOfFiles2
-- segunda contagem do número de arquivos em Downloads
tell application "Finder"
set numberOfFiles2 to count of (files in folder "Macintosh SSD:Users:Roney:Downloads")
end tell
--say "number of downloaded files"
delay 1
say numberOfFiles1
delay 1
say numberOfFiles2
end repeat
-- esperar o download acabar para seguir a macro
repeat while numberOfFiles2 = (numberOfFiles1 + 2)
--esperar enquanto o arquivo não baixado completamente
tell application "Finder"
set numberOfFiles2 to count of (files in folder "Macintosh SSD:Users:Roney:Downloads")
end tell
delay 1
say "downloading"
end repeat
tell application "Microsoft Excel" to activate
tell application "System Events"
tell process "Excel"
delay 0.2
key code 124 --direita
delay 0.2
keystroke "OK"
delay 0.2
key code 36 --enter
delay 0.2
key code 123 --esquerda
delay 0.2
key code 126 --subir
delay 0.2
end tell
end tell
end if
end tell
end repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment