Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applescript + REST?

Does AppleScript have a way of interacting with REST APIs?

I realize I can

do shell script curl
like image 822
themirror Avatar asked May 13 '11 23:05

themirror


People also ask

Does Apple still use AppleScript?

AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system automation tools.

What language does AppleScript use?

AppleScript scripts are composed, by motivated users like yourself, in AppleScript, an English-like language containing many of the verbs, nouns, adjectives, articles and other English language elements we use every day.

Is AppleScript a scripting language?

What Is AppleScript? AppleScript is a scripting language created by Apple. It allows users to directly control scriptable Macintosh applications, as well as parts of macOS itself.

How do I run AppleScript on Mac?

In the Script Editor app on your Mac, click the Run button in the toolbar, or press Command-R, to execute the commands in your script.


1 Answers

I would use curl in

do shell script "#curl script here"

If you need help to get the correct curl statement I recommend postman, It helps me really to generate the right code. But remember If you have these: " to put an escape character in front: \".

So for example if i want to do a POST request to

https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0

the AppleScript would look like this:

do shell script "curl -X POST -H \"Cache-Control: no-cache\" \"https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0\""

And of course you can easy assign the result as a value:

set res to do shell script "curl -X POST -H \"Cache-Control: no-cache\" \"https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0\""

Hope this helps!

like image 170
Jonas Hüsser Avatar answered Nov 13 '22 02:11

Jonas Hüsser