initial commit
This commit is contained in:
commit
db2b871465
6 changed files with 203 additions and 0 deletions
1
README
Normal file
1
README
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Small scripts all under public domain.
|
17
chalmers_login.sh
Executable file
17
chalmers_login.sh
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
USERNAME="uname"
|
||||||
|
PASSWD="password"
|
||||||
|
|
||||||
|
HOST="https://login.nomad.chalmers.se"
|
||||||
|
QUERY="action=Login&login=$USERNAME/net&org=Radius&password=$PASSWD"
|
||||||
|
ANSWER=`curl -d "$QUERY" "$HOST"`
|
||||||
|
|
||||||
|
if echo "$ANSWER" | grep -q "You are logged in"
|
||||||
|
then
|
||||||
|
MESSAGE="Logged in to NOMAD"
|
||||||
|
else
|
||||||
|
MESSAGE="Failed to login to NOMAD"
|
||||||
|
fi
|
||||||
|
|
||||||
|
growlnotify -n "NOMAD" -m "$MESSAGE"
|
106
lastfm.js
Normal file
106
lastfm.js
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
function processUserCommand( command, arguments, connection, view ) {
|
||||||
|
|
||||||
|
if(command.toLowerCase() == "lastfm") {
|
||||||
|
|
||||||
|
arguments = arguments.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
||||||
|
|
||||||
|
function sendMessage(message) {
|
||||||
|
view.echoSentMessageToDisplay(new JVMutableChatMessage(
|
||||||
|
message,
|
||||||
|
connection.localUser())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaults = new NSUserDefaults();
|
||||||
|
|
||||||
|
if(arguments.length > 0 && arguments != "help" && arguments != "getusername") {
|
||||||
|
|
||||||
|
var new_username = arguments;
|
||||||
|
defaults.setObject_forKey_(new_username, "lastfmUsername");
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(arguments == "help") {
|
||||||
|
|
||||||
|
sendMessage('use „/lastfm help“ to show this help');
|
||||||
|
sendMessage('use „/lastfm username“ to set user last.fm username (e.g.: /lastfm johndoe)');
|
||||||
|
sendMessage('use „/lastfm getusername“ to see your default last.fm username');
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(arguments == "getusername") {
|
||||||
|
|
||||||
|
sendMessage('your default last.fm username is: ' + defaults.stringForKey("lastfmUsername"));
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof defaults.stringForKey("lastfmUsername") == "undefined") {
|
||||||
|
|
||||||
|
sendMessage('use „/lastfm username“ to set user last.fm username (e.g.: /lastfm johndoe)');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var req = new XMLHttpRequest();
|
||||||
|
|
||||||
|
req.onreadystatechange = function () {
|
||||||
|
if(req.readyState == 4) {
|
||||||
|
|
||||||
|
if(
|
||||||
|
req.responseXML.getElementsByTagName("lfm")[0].getAttribute("status") == "failed" ||
|
||||||
|
req.responseXML.getElementsByTagName("track").length == 0
|
||||||
|
) sendMessage('user ' + defaults.stringForKey("lastfmUsername") + ' not found on last.fm');
|
||||||
|
else {
|
||||||
|
|
||||||
|
if(new_username) {
|
||||||
|
|
||||||
|
sendMessage('last.fm username is now set to ' + defaults.stringForKey("lastfmUsername"));
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
var track = req.responseXML.getElementsByTagName("track")[0];
|
||||||
|
|
||||||
|
function get(name) {
|
||||||
|
if(
|
||||||
|
track.getElementsByTagName(name) &&
|
||||||
|
track.getElementsByTagName(name)[0] &&
|
||||||
|
track.getElementsByTagName(name)[0].firstChild &&
|
||||||
|
track.getElementsByTagName(name)[0].firstChild.nodeValue &&
|
||||||
|
track.getElementsByTagName(name)[0].firstChild.nodeValue.length > 0
|
||||||
|
) return track.getElementsByTagName(name)[0].firstChild.nodeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = 'is listening to „';
|
||||||
|
text += get("name");
|
||||||
|
text += "“ by „";
|
||||||
|
text += get("artist");
|
||||||
|
text += "“"
|
||||||
|
|
||||||
|
if(get("album")) {
|
||||||
|
text += " from the album „";
|
||||||
|
text += get("album") + "“";
|
||||||
|
}
|
||||||
|
|
||||||
|
var msg = new JVMutableChatMessage(text, connection.localUser());
|
||||||
|
msg.setAction(true);
|
||||||
|
view.sendMessage(msg);
|
||||||
|
view.echoSentMessageToDisplay(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=";
|
||||||
|
url += defaults.stringForKey("lastfmUsername");
|
||||||
|
url += "&api_key=213ac7a42cd7a69b82b7a57c6b067c6c";
|
||||||
|
|
||||||
|
req.open('GET', url, true);
|
||||||
|
req.send(null);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
14
screenshot.sh
Executable file
14
screenshot.sh
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
filename=$1
|
||||||
|
if [ -z $1 ]; then filename="latest"; fi
|
||||||
|
|
||||||
|
screencapture -i "/tmp/latest-screenshot.png"
|
||||||
|
|
||||||
|
if [ -r /tmp/latest-screenshot.png ]
|
||||||
|
then
|
||||||
|
scp /tmp/latest-screenshot.png me@example.com:~/htdocs/s/$filename.png
|
||||||
|
rm /tmp/latest-screenshot.png
|
||||||
|
echo "http://example.com/s/$filename.png" | pbcopy
|
||||||
|
growl -nosticky "Screenshot ready"
|
||||||
|
fi
|
7
tinyurl.sh
Executable file
7
tinyurl.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# tinyurl.sh takes a url from the message buffer and
|
||||||
|
# turns it to a TinyURL which its writes back to it
|
||||||
|
|
||||||
|
curl -s http://tinyurl.com/api-create.php?url=`pbpaste` | pbcopy
|
||||||
|
growlnotify "TinyURL" -m `pbpaste`
|
58
twlastfm.rb
Executable file
58
twlastfm.rb
Executable file
|
@ -0,0 +1,58 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
# This script tweets "I'm listening to ..." via Tweetie
|
||||||
|
# It gets the information from http://last.fm
|
||||||
|
# It also adds a Spotify link
|
||||||
|
|
||||||
|
# This script is OS X only.
|
||||||
|
|
||||||
|
# This script is public domain
|
||||||
|
# Written by Jeena Paradies <spam@jeenaparadies.net> 2009-07-23
|
||||||
|
# Added spotify support 2009-10-27
|
||||||
|
|
||||||
|
# Change the username to yours:
|
||||||
|
username = "yourusername"
|
||||||
|
|
||||||
|
# Save the script somewhere, for example:
|
||||||
|
# ~/Library/Scripts/twlastfm.rb
|
||||||
|
#
|
||||||
|
# Make it executable on the console:
|
||||||
|
# chmod 755 ~/Library/Scripts/twlastfm.rb
|
||||||
|
#
|
||||||
|
# Use Quicksilver to start it.
|
||||||
|
|
||||||
|
require 'uri'
|
||||||
|
require 'net/http'
|
||||||
|
require "rexml/document"
|
||||||
|
|
||||||
|
|
||||||
|
# lastfm
|
||||||
|
url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=";
|
||||||
|
url += username;
|
||||||
|
url += "&api_key=213ac7a42cd7a69b82b7a57c6b067c6c";
|
||||||
|
|
||||||
|
xml_str = Net::HTTP.get_response(URI.parse(url)).body
|
||||||
|
doc = REXML::Document.new(xml_str)
|
||||||
|
track = doc.root.elements[1].elements[1].elements
|
||||||
|
|
||||||
|
song = track["name"].text
|
||||||
|
artist = track["artist"].text
|
||||||
|
album = track["album"].text
|
||||||
|
|
||||||
|
|
||||||
|
# spotify
|
||||||
|
sp_url = "http://ws.spotify.com/search/1/track.xml?q=#{artist} #{song}"
|
||||||
|
xml_str = Net::HTTP.get_response(URI.parse(URI.escape(sp_url))).body
|
||||||
|
doc = REXML::Document.new(xml_str)
|
||||||
|
unless doc.root.elements["track"].attributes["href"].nil?
|
||||||
|
sp_uri = doc.root.elements["track"].attributes["href"]
|
||||||
|
tinyurl = "http://tinyurl.com/api-create.php?url=#{sp_uri}"
|
||||||
|
spotify = Net::HTTP.get_response(URI.parse(tinyurl)).body
|
||||||
|
end
|
||||||
|
|
||||||
|
# text for tweet
|
||||||
|
text = "I\'m listening to „#{song}“ by „#{artist}“"
|
||||||
|
text << " from the album „#{album}“" unless album.nil?
|
||||||
|
text << " ♫ #{spotify}"
|
||||||
|
|
||||||
|
system("open \"tweetie:#{text}\"")
|
Loading…
Add table
Add a link
Reference in a new issue