Created
March 6, 2014 02:36
-
-
Save roneyfraga/9381157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Roney Fraga Souza | |
-- 2014-02-02 | |
-- | |
-- | |
-- script para baixar vários arquivos na páginas Web of Science | |
-- | |
-- é necessário ter no Firefox o plugin Vimium | |
-- que cria atalhos para na página web toda vez que | |
-- aperta-se a telha "f" | |
repeat 2 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 | |
-- abrir baixa de diálogo de download | |
tell application "Firefox" | |
activate | |
tell application "System Events" | |
keystroke "f" | |
delay 1 | |
keystroke "k" | |
delay 1 | |
key code 125 --arrow key | |
delay 0.2 | |
key code 125 | |
delay 0.2 | |
key code 125 | |
delay 0.2 | |
key code 36 --return | |
delay 0.2 | |
end tell | |
end tell | |
-- copiando o início da sequencia no excel | |
tell application "Microsoft Excel" | |
activate | |
tell application "System Events" | |
--tell process "Excel" | |
key code 125 --baixo | |
delay 0.2 | |
keystroke "c" using command down | |
delay 0.2 | |
end tell | |
end tell | |
-- colando o início da sequencia no Chrome | |
tell application "Firefox" | |
activate | |
tell application "System Events" | |
--tell process "Firefox" | |
delay 0.2 | |
key code 125 | |
delay 0.2 | |
key code 48 --tab | |
delay 0.2 | |
keystroke "v" using command down | |
delay 0.2 | |
end tell | |
end tell | |
-- copiando o fim da sequencia no excel | |
tell application "Microsoft Excel" | |
activate | |
tell application "System Events" | |
-- tell process "Excel" | |
key code 124 --direita | |
delay 0.2 | |
keystroke "c" using command down | |
delay 0.2 | |
end tell | |
end tell | |
-- colando o fim da sequencia no Chrome | |
tell application "Firefox" | |
activate | |
tell application "System Events" | |
--tell process "Firefox" | |
delay 0.2 | |
key code 125 | |
delay 0.2 | |
key code 48 --tab | |
delay 0.2 | |
key code 48 --tab | |
delay 0.2 | |
keystroke "v" using command down | |
delay 0.2 | |
key code 48 | |
delay 0.2 | |
--key code 49 --space | |
delay 0.2 | |
key code 125 -- arrow key | |
delay 0.2 | |
key code 125 | |
delay 0.2 | |
--key code 49 --space | |
key code 48 --tab | |
delay 0.2 | |
key code 48 --tab | |
delay 0.2 | |
key code 36 --return | |
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 | |
--fechar última caixa de diálogo | |
tell application "Firefox" | |
activate | |
tell application "System Events" | |
delay 0.2 | |
keystroke "f" | |
delay 1 | |
keystroke "c" | |
delay 1 | |
end tell | |
end tell | |
--inserindo confirmação no excel | |
tell application "Microsoft Excel" | |
activate | |
tell application "System Events" | |
-- tell process "Excel" | |
key code 124 --direita | |
delay 0.2 | |
keystroke "OK" | |
delay 0.2 | |
key code 48 | |
delay 0.2 | |
key code 123 | |
delay 0.2 | |
key code 123 | |
delay 0.2 | |
key code 123 | |
delay 0.2 | |
end tell | |
end tell | |
end repeat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment