Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
fuss:applescript [2015/05/16 04:33]
office
fuss:applescript [2017/02/22 18:30] (current)
Line 1: Line 1:
 +====== Mount All Transmit Favorites ======
  
 +<code applescript>​
 +---------------------------------------------------------------------------
 +--  Copyright (C) Wizardry and Steamworks 2012 - License: GNU GPLv3      --
 +--  Please see: http://​www.gnu.org/​licenses/​gpl.html for legal details, ​ --
 +--  rights of fair usage, the disclaimer and warranty conditions. ​       --
 +---------------------------------------------------------------------------
 +tell application "​Transmit"​
 + repeat with favoriteItem in favorites
 + tell current tab of (make new document at end)
 + connect to favoriteItem with mount
 + close
 + end tell
 + end repeat
 +end tell
 +</​code>​
 +
 +====== Clear All Exif Data In Path or File ======
 +
 +<code applescript>​
 +---------------------------------------------------------------------------
 +--  Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3      --
 +--  Please see: http://​www.gnu.org/​licenses/​gpl.html for legal details, ​ --
 +--  rights of fair usage, the disclaimer and warranty conditions. ​       --
 +---------------------------------------------------------------------------
 +on open exif_purge
 +  repeat with pp in exif_purge
 + set p to POSIX path of pp
 + try
 + do shell script "/​usr/​local/​bin/​exiftool -qqm -overwrite_original -exif:all= -r " & p
 + end try
 + end repeat
 + display dialog "All exif data in path or file \""​ & p & "​\"​ cleaned!"​ buttons {"​OK"​}
 +end open
 +</​code>​
 +
 +====== Use jsBeautify to Format Code ======
 +
 +<code applescript>​
 +---------------------------------------------------------------------------
 +--  Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3      --
 +--  Please see: http://​www.gnu.org/​licenses/​gpl.html for legal details, ​ --
 +--  rights of fair usage, the disclaimer and warranty conditions. ​       --
 +---------------------------------------------------------------------------
 +tell application "​System Events"​
 + tell process "​Finder"​
 + try
 + keystroke "​x"​ using command down
 + end try
 + end tell
 +end tell
 +set txt to the clipboard
 +do shell script "echo " & quoted form of txt & " > /​tmp/​jsbeautify.grimore.org"​
 +set txt to do shell script "/​usr/​local/​share/​npm/​bin/​js-beautify /​tmp/​jsbeautify.grimore.org"​
 +do shell script "rm /​tmp/​jsbeautify.grimore.org"​
 +set the clipboard to txt
 +tell application "​System Events"​
 + tell process "​Finder"​
 + try
 + keystroke "​v"​ using command down
 + end try
 + end tell
 +end tell
 +</​code>​
 +
 +====== Toggle Automatic Proxy On and Off ======
 +
 +Using an application that can be called via ''​Spotlight''​ or ''​QuickSilver''​ or ''​Alfred''​ you can toggle ''​OSX'''​s automatic proxy on and off. This is helpful if you sometimes need to switch your proxy off for certain websites you develop. ​
 +
 +===== Download =====
 +
 +  * {{fuss:​toggle_automatic_proxy.zip}}
 +
 +===== Script =====
 +
 +You can toggle the automatic proxy on OSX via applescript by creating a script with the following contents:
 +
 +<code applescript>​
 +---------------------------------------------------------------------------
 +--  Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3      --
 +--  Please see: http://​www.gnu.org/​licenses/​gpl.html for legal details, ​ --
 +--  rights of fair usage, the disclaimer and warranty conditions. ​       --
 +---------------------------------------------------------------------------
 +set ethernetProxy to do shell script "​networksetup -getproxyautodiscovery ethernet | awk -F': ' '{ print $2 }'"​
 +set wifiProxy to do shell script "​networksetup -getproxyautodiscovery Wi-Fi | awk -F': ' '{ print $2 }'"​
 +if ethernetProxy is "​Off"​ or wifiProxy is "​Off"​ then
 + if ethernetProxy is not "The parameters were not valid."​ then
 + do shell script "​networksetup -setproxyautodiscovery ethernet on"
 + end if
 + if wifiProxy is not "The parameters were not valid."​ then
 + do shell script "​networksetup -setproxyautodiscovery Wi-Fi on"
 + end if
 + display notification "​Automatic proxy is now on." subtitle "​On"​ sound name "​Submarine"​ with title "​Toggle Automatic Proxy"
 +else
 + if ethernetProxy is not "The parameters were not valid."​ then
 + do shell script "​networksetup -setproxyautodiscovery ethernet off"
 + end if
 + if wifiProxy is not "The parameters were not valid."​ then
 + do shell script "​networksetup -setproxyautodiscovery Wi-Fi off"
 + end if
 + display notification "​Automatic proxy is now off." subtitle "​Off"​ sound name "​Submarine"​ with title "​Toggle Automatic Proxy"
 +end if
 +-- Allow notification to show.
 +delay 1
 +
 +</​code>​
 +
 +and then saving it as an application.
 +
 +The AppleScript uses ''/​usr/​sbin/​networksetup''​ in order to make changes to the proxy settings. This means that the script will prompt for a password whenever you call the application. In order to avoid having to type the password every time, you can execute the following command that will make ''/​usr/​sbin/​networksetup''​ not prompt for a password:
 +<code bash>
 +chmod u+s /​usr/​sbin/​networksetup
 +</​code>​
 +
 +Note that this sets the stick bit on ''/​usr/​sbin/​networksetup''​ meaning that any unprivileged user will be able to make changes. Security implications aside, the permission repair scripts that OSX runs periodically may unset the sticky bit. On recent OSX versions, you may need to disable the [[fuss/​osx#​disable_system_integrity_protection|SIP file integrity checks]] in order to make ''​networksetup''​ SUID root otherwise you will be prompted for a password (which ain't that bad).

fuss/applescript.txt ยท Last modified: 2017/02/22 18:30 (external edit)

Access website using Tor Access website using i2p


For the copyright, license, warranty and privacy terms for the usage of this website please see the license, privacy and plagiarism pages.