• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Was gibt es Schöneres als den Mai draußen in der Natur mit allen Sinnen zu genießen? Lasst uns teilhaben an Euren Erlebnissen und macht mit beim Thema des Monats Da blüht uns was! ---> Klick

[AppleScript] hosts Modifikation mit Chrome

Kernelpanik

Maren Nissen
Registriert
05.03.04
Beiträge
2.303
Hallo,
für alle die sich mit hosts auskennen hier ein Service der die Domain im aktuellen Fenster auf 0.0.0.0 leitet. (hosts add blocker)

Code:
tell application "Google Chrome"
    set var to URL of active tab of first window
end tell
set {hostURL, catHosts} to {do shell script "echo " & quoted form of var & "|awk -F/ '{print $3}'", do shell script "cat /etc/hosts"}
set blockDomain to "0.0.0.0 " & hostURL
tell application "Google Chrome"
    if catHosts contains blockDomain then
        display alert "'hosts' already contains:" message blockDomain as critical
    else
        display dialog "Ban " & quoted form of hostURL & " in hosts?" with icon 1 with title "BanInHosts"
        my hostWrite(blockDomain)
    end if
end tell
on hostWrite(x)
    do shell script "echo " & x & " >> /etc/hosts" with administrator privileges
end hostWrite

Mit Automator einen Dienst erstellen und wie im Bild konfigurieren.

Bildschirmfoto 2017-03-28 um 09.23.08.png
 
Zuletzt bearbeitet: