Jump to content

Getting Scripts from v1 work in 2


Recommended Posts

Hello,

I am really new to scripts but I used some in Alfred v1.

Scripts like Bluetooth-Toggle or Wi-Fi-toggle and AppleScripts like Starfish or Caffeine Manager.

 

Now with version 2 beta I wanted to import some manually by copying the text.

 

For Example: Bluetooth-Toggle

I said Keyword (Input) and combined it with run script (Actions)

Script: 

./bluetooth.py

 

 

Another Caffeine Manager:

 

I said Keyword (Input) and combined it with run applescript (Actions)

Script: 

(* This is an unofficial manager for Caffeine (http://lightheadsw.com/caffeine/) created by Sebastian of Zibity. It is an easy way to toggle Caffeine on and off.
	Usage: "caff"

If you have any questions or suggestions, please send me a message via my website: http://www.zibity.com

If you want more cool Alfred extensions like these, take a look at http://www.zibity.com/alfred.html for all of my other extensions.

If you like this extension, please consider donating to support the continued development of things like this: http://donate.zibity.com


*)

--- SCRIPT BEGINS HERE ---
try
	tell application "Caffeine"
		if active is false then
			turn on
			tell application "Growl" to notify with name "Extension Output" title "Caffeine has been activated." description "Caffeine Manager has activated Caffeine." application name "Alfred" identifier "caff" icon of application "Caffeine"
		else
			turn off
			tell application "Growl" to notify with name "Extension Output" title "Caffeine has been deactivated." description "Caffeine Manager has deactivated Caffeine." application name "Alfred" identifier "caff" icon of application "Caffeine"
		end if
	end tell
end try

 

Non of this ways really worked for me. Do you have any suggestions for me what I did wrong?

 

Link to comment

Thanks! Now It works with AppleScripts but not with the following ones:

 

Bluetooth-toggle

./bluetooth.py

WiFi-toggle

#Function to search keychain for the network password
get_pw () {
 if [ "$1" ]
 then
  security 2>&1 >/dev/null  find-generic-password -ga AirPort -l "$1" | cut -d '"' -f 2 | grep -v security:
 fi
}
#Find the device name
DEVICE=$(networksetup -listallhardwareports | grep -A 2 -E "AirPort|Wi-Fi" | grep -m 1 -o -e en[0-9]);
#Toggle or change network?
case "{query}" in
"")
 #Toggle the power of the Wi-Fi/Airport
 if [ $(networksetup -getairportpower $DEVICE | grep -c On) == 0 ]
 then
  networksetup -setairportpower $DEVICE On
  echo "Wi-Fi enabled.";
 else
  networksetup -setairportpower $DEVICE Off
  echo "Wi-Fi disabled.";
 fi
;;
"?")
  echo $(networksetup -getairportnetwork $DEVICE)
  echo
  networksetup -getinfo Wi-Fi
;;
*)
 #Change network - Make sure that the Airport is on
 if [ $(networksetup -getairportpower $DEVICE | grep -c On) == 0 ]
 then
  networksetup -setairportpower $DEVICE On
 fi
 #Fuzzy match to known networks
 NETWORK=$(networksetup -listpreferredwirelessnetworks en1 | egrep -im 1 "[[:alnum:]]*{query}[[:alnum:]]*$");
 #If a match is found - try to connect to Network
 if [ -z "$NETWORK" ]
 then
  echo "Unable to match \"{query}\" to a know network.";
 else
  ERROR=$(networksetup -setairportnetwork en1 "$(echo $NETWORK)" $(get_pw "$(echo $NETWORK)") );
  if [ -z "$ERROR" ]
  then
   echo "Successfully connected to network $NETWORK.";
  else
   echo $ERROR;
  fi
 fi
;;
esac

 

Are these Python-Scripts and follow other rules?

Link to comment
WiFi-toggle

 

This is a Bash script. I have made a new version for Alfred 2, you can finde it here:

https://github.com/aiyodk/Alfred-Extensions/raw/master/AlfredApp_2.x/Wi-Fi-Toggle/Wi-Fi%20Toggle.alfredworkflow

 

This new workflow also shows the current network name and IP-address when connected to a network.

 

 

You can see all my Alfred 2 workflows here: http://www.aiyo.dk/alfredapp/v2/

 

Cheers

Link to comment
  • Vero locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...