Economizing Technology >

safari-ctl - Command Line Tool To Control Safari for MacOS


A Command Line Tool to Control Safari for MacOS. (Browsing/FillingForm/GetSetCopyURL/JavascriptInjection/GetTitle/Search)

### Get current URL on Safari

$ safari-ctl
https://github.com

### Copy current URL on Safari to the clipboard

$ safari-ctl -s

### Navigating by command line

$ safari-ctl -m
# marks all <a> with numbers

$ safari-ctl -a 32
# click 32'th <a>

$ safari-ctl -b
# history back

### Filing form

$ safari-ctl -M
# marks all <input> with numbers

$ safari-ctl -A 0 -I 'Japan'
# Fill 0th input with 'Japan'

$ safari-ctl -A 1
# click 1st input button

### Javascript Injection

$  safari-ctl -j 'document.getElementById("sb_form_q").value="Japan"'
Japan

Index

  1. Install
  2. Command line
  3. Prepare
  4. Options
  5. Examples
  6. Change Log
  7. Idea
  8. Comments

Install

npm i -g safari-ctl

You must enable the 'Allow JavaScript from Apple Events' option in Safari's Develop menu to use some features.

Command line

safari-ctl [options]

A Command Line Tool to control Safari for MacOS. (Browsing/FillingForm/GetSetCopyURL/JavascriptInjection/GetTitle/Search)

Copyright (C) 2019-2019 @kssfilo(https://kanasys.com/gtech/)

Prepare

(*)You must enable the 'Allow JavaScript from Apple Events' option in Safari's Develop menu to use some features.

Options

- h              show this help
- ?              
- d              debug mode
- p              print current Safari's URL(default)
- t              print current Safari's title
- g              print selected string on current Safari's tab
- c              copy current Safari's URL into the clipboard
- s <URL>        set <URL> to Safari's active tab
- S <URL>        same as -s but set focus to Safari
- q <query>      search <query> to Safari's active tab
- Q <URL>        same as -q but set focus to Safari
- m              marks all <a> link with number to click by next -a command(*)
- a <number>     click <number> link. you can know link number by -m command(*)
- M              marks all <input> with number to click/set by next -A command(*)
- A <number>     click <number> input. you can know input number by -M command(*)
- I <string>     works with -A, Input <string> instead of click. for filling form(*)
- b              history back(*)
- f              history forward(*)
- n              scroll to next page(*)
- N              scroll to previous page (*)
- j <javascript> run <javascript> on active tab(*)
- J <javascript> same as s but set focus to Safari(*)

Examples

Get current URL on Safari

$ safari-ctl
https://github.com

Copy current URL on Safari to the clipboard

$ safari-ctl -s

Open specified URL on Safari

$ safari-ctl -s 'http://github.com'
# withoug focus

$ safari-ctl -S 'github.com'
# with focus(omiting scheme->appends https://)

Gets window title

$ safari-ctl -t
$ safari-ctl -m
# marks all <a> with numbers

$ safari-ctl -a 32
# click 32'th <a>

$ safari-ctl -b
# history back

$ safari-ctl -M
# marks all <input> with numbers

$ safari-ctl -A 0 -I 'Japan'
# Fill 0th input with 'Japan'

$ safari-ctl -A 1
# click 1st input button

Searchs Bing with word "Japan" (JavaScript injection)

$  safari-ctl -s 'https://bing.com'
$  safari-ctl -j 'document.getElementById("sb_form_q").value="Japan";document.getElementById("sb_form_go").click()'
$  safari-ctl -j 'document.getElementById("sb_form_q").value'
Japan

Change Log

Idea

Popular Articles from This Page

Economizing Technology >

Comments

Top Page

Economizing Technology > safari-ctl - Command Line Tool To Control Safari for MacOS