AppleScript to download file
I need to write an AppleScript to open Safari and go to https://www.stats.govt.nz/large-datasets/csv-files-for-download/ to download the first csv file
applescript
add a comment |
I need to write an AppleScript to open Safari and go to https://www.stats.govt.nz/large-datasets/csv-files-for-download/ to download the first csv file
applescript
1
This is not a question, it is outsourcing a task or homework.
– RalfFriedl
Nov 21 '18 at 6:47
1
How To Ask
– Halil İbrahim
Nov 21 '18 at 6:48
add a comment |
I need to write an AppleScript to open Safari and go to https://www.stats.govt.nz/large-datasets/csv-files-for-download/ to download the first csv file
applescript
I need to write an AppleScript to open Safari and go to https://www.stats.govt.nz/large-datasets/csv-files-for-download/ to download the first csv file
applescript
applescript
asked Nov 21 '18 at 6:45
SpringSpring
1
1
1
This is not a question, it is outsourcing a task or homework.
– RalfFriedl
Nov 21 '18 at 6:47
1
How To Ask
– Halil İbrahim
Nov 21 '18 at 6:48
add a comment |
1
This is not a question, it is outsourcing a task or homework.
– RalfFriedl
Nov 21 '18 at 6:47
1
How To Ask
– Halil İbrahim
Nov 21 '18 at 6:48
1
1
This is not a question, it is outsourcing a task or homework.
– RalfFriedl
Nov 21 '18 at 6:47
This is not a question, it is outsourcing a task or homework.
– RalfFriedl
Nov 21 '18 at 6:47
1
1
How To Ask
– Halil İbrahim
Nov 21 '18 at 6:48
How To Ask
– Halil İbrahim
Nov 21 '18 at 6:48
add a comment |
2 Answers
2
active
oldest
votes
Rather than doing your work for you by providing you with a code snippet to accomplish this task, I will instead provide you with a great resource. Cube MG has a bunch of tutorials that are really helpful for interacting with web page elements via Safari. Check it out here: http://www.cubemg.com/how-to-click-a-button-on-a-web-page-with-applescript/
There are other ways that you could approach something like this such as using the command line but that is a bit more advanced. Check out Cube MG and see what you can learn!
add a comment |
tell application "Safari"
make new document with properties ¬
{URL:"https://www.stats.govt.nz/large-datasets/csv-files-for-download/"}
repeat
if the front document's source contains "What are CSV files?" then ¬
exit repeat
delay 0.5
end repeat
tell the front document to set CSVfiles to ¬
do JavaScript "Array.from(document.links,
x=>x.href)
.filter(x=>x.indexOf('.csv')!=-1);"
end tell
This gets you the links to all the CSV files. To extract the first one, use item 1 of CSVfiles
.
NB. Don't forget to enable Allow JavaScript from Apple Events in Developer menu (a hidden menu, made visible through Preferences > Advanced > Show Develop menu in menu bar)
A few things about your answer: 1. Copy and pasting the code as is into Script Editor errors on compile,Expected expression but found “tell”.
. Had to changeset CSVfiles to tell the front document to ¬
totell the front document to set CSVfiles to ¬
for it to work. 2.repeat while the name of front document = "Untitled"
is unreliable as thename of document 1
can change before the page is completely loaded and{}
can/will be returned for the JavaScript command. 3. Allow JavaScript from Apple Events on the hidden Developer menu in Safari needs to be checked, which isn't by default.
– user3439894
Nov 24 '18 at 7:09
Many thanks, @user3439894
– CJK
Nov 24 '18 at 7:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406580%2fapplescript-to-download-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Rather than doing your work for you by providing you with a code snippet to accomplish this task, I will instead provide you with a great resource. Cube MG has a bunch of tutorials that are really helpful for interacting with web page elements via Safari. Check it out here: http://www.cubemg.com/how-to-click-a-button-on-a-web-page-with-applescript/
There are other ways that you could approach something like this such as using the command line but that is a bit more advanced. Check out Cube MG and see what you can learn!
add a comment |
Rather than doing your work for you by providing you with a code snippet to accomplish this task, I will instead provide you with a great resource. Cube MG has a bunch of tutorials that are really helpful for interacting with web page elements via Safari. Check it out here: http://www.cubemg.com/how-to-click-a-button-on-a-web-page-with-applescript/
There are other ways that you could approach something like this such as using the command line but that is a bit more advanced. Check out Cube MG and see what you can learn!
add a comment |
Rather than doing your work for you by providing you with a code snippet to accomplish this task, I will instead provide you with a great resource. Cube MG has a bunch of tutorials that are really helpful for interacting with web page elements via Safari. Check it out here: http://www.cubemg.com/how-to-click-a-button-on-a-web-page-with-applescript/
There are other ways that you could approach something like this such as using the command line but that is a bit more advanced. Check out Cube MG and see what you can learn!
Rather than doing your work for you by providing you with a code snippet to accomplish this task, I will instead provide you with a great resource. Cube MG has a bunch of tutorials that are really helpful for interacting with web page elements via Safari. Check it out here: http://www.cubemg.com/how-to-click-a-button-on-a-web-page-with-applescript/
There are other ways that you could approach something like this such as using the command line but that is a bit more advanced. Check out Cube MG and see what you can learn!
answered Nov 21 '18 at 12:56
Howard DesignsHoward Designs
1
1
add a comment |
add a comment |
tell application "Safari"
make new document with properties ¬
{URL:"https://www.stats.govt.nz/large-datasets/csv-files-for-download/"}
repeat
if the front document's source contains "What are CSV files?" then ¬
exit repeat
delay 0.5
end repeat
tell the front document to set CSVfiles to ¬
do JavaScript "Array.from(document.links,
x=>x.href)
.filter(x=>x.indexOf('.csv')!=-1);"
end tell
This gets you the links to all the CSV files. To extract the first one, use item 1 of CSVfiles
.
NB. Don't forget to enable Allow JavaScript from Apple Events in Developer menu (a hidden menu, made visible through Preferences > Advanced > Show Develop menu in menu bar)
A few things about your answer: 1. Copy and pasting the code as is into Script Editor errors on compile,Expected expression but found “tell”.
. Had to changeset CSVfiles to tell the front document to ¬
totell the front document to set CSVfiles to ¬
for it to work. 2.repeat while the name of front document = "Untitled"
is unreliable as thename of document 1
can change before the page is completely loaded and{}
can/will be returned for the JavaScript command. 3. Allow JavaScript from Apple Events on the hidden Developer menu in Safari needs to be checked, which isn't by default.
– user3439894
Nov 24 '18 at 7:09
Many thanks, @user3439894
– CJK
Nov 24 '18 at 7:15
add a comment |
tell application "Safari"
make new document with properties ¬
{URL:"https://www.stats.govt.nz/large-datasets/csv-files-for-download/"}
repeat
if the front document's source contains "What are CSV files?" then ¬
exit repeat
delay 0.5
end repeat
tell the front document to set CSVfiles to ¬
do JavaScript "Array.from(document.links,
x=>x.href)
.filter(x=>x.indexOf('.csv')!=-1);"
end tell
This gets you the links to all the CSV files. To extract the first one, use item 1 of CSVfiles
.
NB. Don't forget to enable Allow JavaScript from Apple Events in Developer menu (a hidden menu, made visible through Preferences > Advanced > Show Develop menu in menu bar)
A few things about your answer: 1. Copy and pasting the code as is into Script Editor errors on compile,Expected expression but found “tell”.
. Had to changeset CSVfiles to tell the front document to ¬
totell the front document to set CSVfiles to ¬
for it to work. 2.repeat while the name of front document = "Untitled"
is unreliable as thename of document 1
can change before the page is completely loaded and{}
can/will be returned for the JavaScript command. 3. Allow JavaScript from Apple Events on the hidden Developer menu in Safari needs to be checked, which isn't by default.
– user3439894
Nov 24 '18 at 7:09
Many thanks, @user3439894
– CJK
Nov 24 '18 at 7:15
add a comment |
tell application "Safari"
make new document with properties ¬
{URL:"https://www.stats.govt.nz/large-datasets/csv-files-for-download/"}
repeat
if the front document's source contains "What are CSV files?" then ¬
exit repeat
delay 0.5
end repeat
tell the front document to set CSVfiles to ¬
do JavaScript "Array.from(document.links,
x=>x.href)
.filter(x=>x.indexOf('.csv')!=-1);"
end tell
This gets you the links to all the CSV files. To extract the first one, use item 1 of CSVfiles
.
NB. Don't forget to enable Allow JavaScript from Apple Events in Developer menu (a hidden menu, made visible through Preferences > Advanced > Show Develop menu in menu bar)
tell application "Safari"
make new document with properties ¬
{URL:"https://www.stats.govt.nz/large-datasets/csv-files-for-download/"}
repeat
if the front document's source contains "What are CSV files?" then ¬
exit repeat
delay 0.5
end repeat
tell the front document to set CSVfiles to ¬
do JavaScript "Array.from(document.links,
x=>x.href)
.filter(x=>x.indexOf('.csv')!=-1);"
end tell
This gets you the links to all the CSV files. To extract the first one, use item 1 of CSVfiles
.
NB. Don't forget to enable Allow JavaScript from Apple Events in Developer menu (a hidden menu, made visible through Preferences > Advanced > Show Develop menu in menu bar)
edited Nov 24 '18 at 10:36
answered Nov 24 '18 at 2:57
CJKCJK
2,5981216
2,5981216
A few things about your answer: 1. Copy and pasting the code as is into Script Editor errors on compile,Expected expression but found “tell”.
. Had to changeset CSVfiles to tell the front document to ¬
totell the front document to set CSVfiles to ¬
for it to work. 2.repeat while the name of front document = "Untitled"
is unreliable as thename of document 1
can change before the page is completely loaded and{}
can/will be returned for the JavaScript command. 3. Allow JavaScript from Apple Events on the hidden Developer menu in Safari needs to be checked, which isn't by default.
– user3439894
Nov 24 '18 at 7:09
Many thanks, @user3439894
– CJK
Nov 24 '18 at 7:15
add a comment |
A few things about your answer: 1. Copy and pasting the code as is into Script Editor errors on compile,Expected expression but found “tell”.
. Had to changeset CSVfiles to tell the front document to ¬
totell the front document to set CSVfiles to ¬
for it to work. 2.repeat while the name of front document = "Untitled"
is unreliable as thename of document 1
can change before the page is completely loaded and{}
can/will be returned for the JavaScript command. 3. Allow JavaScript from Apple Events on the hidden Developer menu in Safari needs to be checked, which isn't by default.
– user3439894
Nov 24 '18 at 7:09
Many thanks, @user3439894
– CJK
Nov 24 '18 at 7:15
A few things about your answer: 1. Copy and pasting the code as is into Script Editor errors on compile,
Expected expression but found “tell”.
. Had to change set CSVfiles to tell the front document to ¬
to tell the front document to set CSVfiles to ¬
for it to work. 2. repeat while the name of front document = "Untitled"
is unreliable as the name of document 1
can change before the page is completely loaded and {}
can/will be returned for the JavaScript command. 3. Allow JavaScript from Apple Events on the hidden Developer menu in Safari needs to be checked, which isn't by default.– user3439894
Nov 24 '18 at 7:09
A few things about your answer: 1. Copy and pasting the code as is into Script Editor errors on compile,
Expected expression but found “tell”.
. Had to change set CSVfiles to tell the front document to ¬
to tell the front document to set CSVfiles to ¬
for it to work. 2. repeat while the name of front document = "Untitled"
is unreliable as the name of document 1
can change before the page is completely loaded and {}
can/will be returned for the JavaScript command. 3. Allow JavaScript from Apple Events on the hidden Developer menu in Safari needs to be checked, which isn't by default.– user3439894
Nov 24 '18 at 7:09
Many thanks, @user3439894
– CJK
Nov 24 '18 at 7:15
Many thanks, @user3439894
– CJK
Nov 24 '18 at 7:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406580%2fapplescript-to-download-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This is not a question, it is outsourcing a task or homework.
– RalfFriedl
Nov 21 '18 at 6:47
1
How To Ask
– Halil İbrahim
Nov 21 '18 at 6:48