Mittwoch, 28. Oktober 2015

AppleScript to quickly change your dns setting

Here ist a neat little applescript to quickly change your DNS settings.
Useful when you often have to switch between your routers DNS and for example Unblock-Us.


set dnsList to {"Unblock US", "Default"}
set selectedDNS to {choose from list dnsList with title "DNS Server to set"}

display dialog "Admin Password to change network settings" default answer ""
set pw to text returned of result

log item 1 of selectedDNS
log "test"

if item 1 of selectedDNS is {"Unblock Us"} then
 log "Unblock US"
 do shell script "networksetup -setdnsservers Wi-Fi 208.122.23.23" user name "fred" password pw with administrator privileges
else if item 1 of selectedDNS is {"Default"} then
 log "Default DNS"
 do shell script "networksetup -setdnsservers Wi-Fi 192.168.1.1" user name "fred" password pw with administrator privileges
else
 log "Got no valid value"
end if

Dienstag, 25. August 2015

Find and delete files older than X days (Linux Shell)

From time to time I need to clean certain folders from log files.

Here is a handy command that deletes files

  • in current folder 
  • that are older than 2 days
  • and that have the extension .log 


 find . -type f -mtime +2 -name '*.log' -exec rm {} \;

Freitag, 6. Februar 2015

Apple script to connect to AFP network shares with password prompt

I have Synology NAS and thus connect several folders as network shares.
Since the connection often gets lost, especially after the Mac is going to sleep I wrote a little script.
The script prompts for password so you don't have to expose it.
Enjoy ;)


display dialog "Password to connect to NAS" default answer ""
set nas_pw to text returned of result
try
mount volume "afp://username:" & nas_pw & "@nas_ip_or_dns/photo"
mount volume "afp://username:" & nas_pw & "@nas_ip_or_dns/home"
mount volume "afp://username:" & nas_pw & "@nas_ip_or_dns/music"
mount volume "afp://username:" & nas_pw & "@nas_ip_or_dns/video"
mount volume "afp://username:" & nas_pw & "@nas_ip_or_dns/share"
end try