DEV Community

Cover image for AppleScript Automation.
A Serputov
A Serputov

Posted on

AppleScript Automation.

ShortStory.

A few weeks ago, I was curious about accessing different devices on my network. After a long time researching, I found that it's accessible simple to ssh into my local machine IP address.

In my subsequent work, I found something exciting. I was able to control the brightness of my Macbook Pro from my iMac terminal, and one time I left my table to take a quick break for breakfast, and the monitor on my laptop went to sleep. I pressed enter and saw the log-in page, BUT I could still use my laptop via ssh on the terminal.

I thought it would be interesting to access the keyboard via terminal, but it is hard to do with .sh/bs.

Behind a research work, I found that AppleScript is a thing. We can automate and ask it to do something exciting.
The first thing I did was create a "google" function in the terminal that opens google search with the flag as a query input -

google "What's your search?".
Enter fullscreen mode Exit fullscreen mode

Second thing was this code, that opens: Spotlight - type Notepad and prints HelloWorld.

Image description

Code >

tell application "System Events"
    delay 0.5
    keystroke space using command down
    delay 0.5
    keystroke "Text"
    delay 0.5
    keystroke "Edit"
    delay 0.5
    keystroke return
    delay 1
    keystroke "Hello world!"
end tell
Enter fullscreen mode Exit fullscreen mode

Conclusion

Automation!

⚠️ Previous Blog Post Tips And Tricks About Shell & CURL [Link]
This post is the best for short commands.

⚠️ Future Blog Post About Collaborative WhiteBoard with Node.js + React.js + AWS(EC2): [Link]

Links

🖇 Follow me on GitHub

🖇 Follow me on Twitter

_p.s This post was made out of my curiosity

Top comments (0)