applescript
Applescript från kommandoraden Terminal
Sök…
Introduktion
Applescript är ett kraftfullt skriptspråk som kan användas direkt från kommandoraden Terminal för att utföra en mängd uppgifter.
Alla exempel som listas i detta avsnitt är avsedda att användas från terminalapplikationen.
Skaffa den aktuella URL: en i Safari eller Google Chrome
Från Terminal- kommandoraden
Hämta den aktuella URL: en från Safari
osascript -e 'tell app "safari" to get the url of the current tab of window 1'
Skaffa den aktiva URL: en i Google Chrome
osascript -e 'tell app "google chrome" to get the url of the active tab of window 1'
Skaffa titeln på den aktuella sidan i Safari eller Google Chrome
Få namnet på webbsidan i Safari
osascript -e 'tell app "safari" to get the name of the current tab of window 1'
Få titeln på webbsidan i Google Chrome
osascript -e 'tell app "google chrome" to get the title of the active tab of window 1'
Använd ett Applescript som skalfunktion
Du är inte begränsad till enda rad Applescript-kod. Här tar vi de två föregående exemplen och kombinerar dem till en enda funktion.
#!/bin/bash
pageinfo() {
osascript -e \
'tell app "safari"
tell the current tab of window 1
return {url & "\n" & name}
end tell
end tell'
}
Modified text is an extract of the original Stack Overflow Documentation
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow