Posted
on Wednesday, 05th October 2011, 01:55 PM,
by
Chris,
under
Coding.
I was looking around for a means to grab the URL of the currently playing track in Spotify earlier, but couldn’t find anything.
I rattled together an AppleScript to do just that and copy the result, including the track and artist name, to your clipboard.
tell application "Spotify"
set theTrack to name of the current track
set theArtist to artist of the current track
set theAlbum to album of the current track
set track_id to id of current track
end tell
set AppleScript's text item delimiters to ":"
set track_id to third text item of track_id
set AppleScript's text item delimiters to {""}
set realurl to ("http://open.spotify.com/track/" & track_id)
set theString to theTrack & " - " & theArtist & ": " & realurl
set the clipboard to theString
“Feel Like Makin’ Love – Bad Company: http://open.spotify.com/track/3HKthdb7Ejnydb74BvmQW0”
I used a few bits of this Ceonceited Software forum post for pointers on accessing Spotify details via AppleScript.
Enjoy,
- Chris
Posted
on Wednesday, 14th September 2011, 09:20 AM,
by
Chris,
under
Personal.
I had a strange dream recently, unlike the strange dreams I usually have – nobody was a monster and there was no killing involved.
Every person in the world is given a clay pot, in my dream there was no notion of where they come from, just that everyone always has one. Inside this pot is a clay teapot. All of them, pots and teapots, are made of terracotta; some are ornate, some decorated, others are just plain clay; regardless of how they look, they all serve the same purpose.
Read the rest of this entry »
Posted
on Wednesday, 06th October 2010, 12:34 PM,
by
Chris,
under
Coding.
If you’ve ever wanted to convert a date of a UK vehicle into a nice looking representation of the year code then you’ve came to the right place!
I’ve written a small PHP function to convert a given date to one of the following formats:
-
Dates before Feb 1963
-
[YEAR]
-
i.e. “1960″, “1962″
-
Dates from Feb 1963 – August 2001
-
[SUFFIX/PREFIX LETTER] ([YEAR])
-
i.e. “V (1999)”, “A (1983)”
-
Dates from September 2001 onwards
-
[AGE IDENTIFIER] ([YEAR])
-
i.e. “57 (2007)”, “57 (2008)”, “60 (2010)”
Read the rest of this entry »
Posted
on Wednesday, 14th April 2010, 09:36 AM,
by
Chris,
under
General.
This small set of scripts should give you a starting point for filtering the valid input to certain form fields to ensure that you shouldn’t end up with input that you don’t want*.
Basically you’d have the following javascript functions defined:
function isNumber( evt ) {
valid = true;
if( evt.which || ( evt.which != 0 && evt.charCode != 0 ) ) {
var charCode = ( evt.which ) ? evt.which : event.keyCode;
if( charCode > 31 && ( charCode < 48 || charCode > 57 ) ) {
valid = false;
}
}
return valid;
}
function isValidEmailCharacter( evt ) {
valid = true;
if( evt.which == null || ( evt.which != 0 && evt.charCode != 0 ) ) {
var charCode = ( evt.which ) ? evt.which : event.keyCode;
var char = String.fromCharCode( charCode );
var re = new RegExp( /([0-9A-Za-z-_@.])/ );
valid = re.test( char );
}
return valid;
}
function isValidPhoneCharacter( evt ) {
valid = true;
if( evt.which == null || ( evt.which != 0 && evt.charCode != 0 ) ) {
var charCode = ( evt.which ) ? evt.which : event.keyCode;
var char = String.fromCharCode( charCode );
var re = new RegExp( /([0-9+\s\[\]])/ );
valid = re.test( char );
}
return valid;
}
Read the rest of this entry »
Posted
on Friday, 09th April 2010, 11:10 AM,
by
Chris,
under
Coding.
Something I’ve been playing with recently that’s not very well documented is using JavaScript to retrieve and to update the current page anchor from a URL.
It’s very simple to do. In order to retrieve the page anchor (i.e. get test from http://chris-miller.org/88#test:
var anchor = self.document.location.hash.substring( 1 );
Setting the anchor to update, for example to http://chris-miller.org/88#newAnchor it can be achived using:
self.document.location.hash = "newAnchor";
Very useful for creating permalinks to AJAX loaded content or JS popups.
- Chris
Recent Comments