0 comments Saturday, August 9, 2008

iPhone expert Jonathan Zdziarski recently discovered what he thought was a remote killswitch for iPhone apps: a blacklist located at https://iphone-services.apple.com/clbl/unauthorizedApps. He thought it could be used "to disable applications that the user has already downloaded and paid for." However, Daring Fireball's John Gruber found out from a source that the list only serves to prevent malicious apps from accessing location information.

In order to test the blacklist out, I set up a DNS server on my Mac that pointed iphone-services.apple.com to my own web server. I then added the unauthorizedApps file in the clbl directory of my server. I switched the iPhone to use the DNS server on my Mac when on my WiFi network, and then tested the blacklist URL in Safari. It worked, so I tried modifying the file to block the Maps app from getting location info:

{
"Date Generated" = "2008-08-10 00:24:27 Etc/GMT";
"BlackListedApps" = {
"com.apple.Maps" = {
"Description" = "Being really bad!";
"App Name" = "Apple Google Maps";
"Date Revoked" = "2004-02-01 08:00:00 Etc/GMT";
};
};
}


When I opened the Maps app and told it to find my location, it gave me the following error message:


Otherwise, it worked normally. Once I removed the Maps app from the blacklist, it could find my location once again.

1 comments Friday, July 11, 2008

I have found a better way of saving NewNewsWire articles to read later in Safari on my desktop or iPhone:

LaterLoop is a site that allows you to add links to your reading list, then later easily view those links in your desktop or mobile browser. This is similar to Instapaper, Delicious (using a toread tag), etc.

I like the interface better, however, because when you save a link, rather than opening a pop-up or redirecting you to a new page to save the link, the page simply flashes. This is a nice feature when using it in the browser, but it ends up being crucial to being able to use it within NetNewsWire.

I hadn't realized this when I made an AppleScript script to save NNW articles to Delicious, but NNW has the ability to run JavaScript "bookmarklets" located in the Scripts menu. Normally, you can take a bookmarklet such as LaterLoop's "Save for Later" bookmarklet, copy the address, paste it in a text file whose name ends in .js, and place it in NNW's Scripts folder (you can find this folder by clicking "Open Scripts Folder" from the Scripts menu in NNW).

Unfortunately, NetNewsWire returns the homepage of the RSS feed as the current URL rather than the URL of the specific article. To correct this, I had to download and modify the LaterLoop script and bookmarklet so that they pull the actual URL of the article.

To use my modified version, save this as ll.js and remember which directory you saved it in:

(function(){
__ll_u = 'http://www.laterloop.com/post/?key=' + document._ll;
document._ll = '';
function getFirstElementByClassName(tag, className, dom){
var elems = dom.getElementsByTagName(tag);
for (var i = 0; i < elems.length; i++) {
var elem = elems[i];
if (elem.className.indexOf(className) != -1)
return elem;
}
return null;
}
function unescapeHTML(str, doc){
var dom = doc || document;
var div = dom.createElement('div');
div.innerHTML = str;
return div.childNodes[0].nodeValue;
}
function getGoogleReaderItem(){
var page_url = null, page_title = null, source_title = '', do_save = false, is_google_reader = false;
var google_reader = /\/\/www\.google\.com\/reader\/view/ig;
var location = dom.getElementById('newsItemTitle').firstChild.getAttribute('href');
var dom = window.document;
if (location.match(google_reader)) { //if (page_url.indexOf('//www.google.com/reader') != -1) {
is_google_reader = true;
var current_item = dom.getElementById('current-entry');
if (current_item) {
var h2 = current_item.getElementsByTagName('h2');
var link = getFirstElementByClassName('a', 'entry-original', current_item);
var stream_title = getFirstElementByClassName('span', 'entry-source-title', current_item);
var is_stream_title_and_not_shared_item = !stream_title.getElementsByTagName('img') || stream_title.getElementsByTagName('img').length == 0;
if (stream_title) {
if (is_stream_title_and_not_shared_item) {
source_title = stream_title.innerHTML;
}
else {
stream_title = getFirstElementByClassName('a', 'entry-source-title', current_item);
source_title = stream_title.innerHTML;
}
}
if (source_title == '') {
stream_title = dom.getElementById('chrome-stream-title');
if (stream_title) {
stream_title = stream_title.getElementsByTagName('a');
if (stream_title && stream_title.length) {
source_title = stream_title[0].innerHTML;
}
}
}
if (h2.length && link) {
page_title = unescapeHTML(h2[0].innerHTML, dom);
page_url = link.href;
source_title = unescapeHTML(source_title, dom);
}
}
}

if (page_url && page_title && page_url != '' && page_title != '') {
do_save = true;
}

return {
is_google_reader: is_google_reader,
do_save: do_save,
url: page_url,
title: page_title,
source: source_title
};

}
var google_reader_item = null;
try {
google_reader_item = getGoogleReaderItem();
}
catch(x) {}

__ll_w = window;
__ll_d = __ll_w.top.document;
__ll_e = encodeURIComponent;

var do_save = true;
var do_fade = true;

if (google_reader_item && google_reader_item.is_google_reader) {
if (google_reader_item.do_save) {
var referrer = 'http://www.google.com/reader/view/#bkml1';
__ll_u += '&title=' + __ll_e(google_reader_item.title) + '&url=' + __ll_e(google_reader_item.url) + '&via=' + __ll_e(referrer) + '&greader=1&source_title=' + __ll_e(google_reader_item.source) + '&src=wk&v=1&fmt=js&t=' + (new Date().getTime());
do_fade = false;
}
else {
alert('LaterLoop could not identify which item is currently selected. Please click on a story and try again.')
do_save = false;
}
}
else {
__ll_u += '&title=' + __ll_e(__ll_d && __ll_d.title.replace(/^\[(Saving...|Saved)\]\s/, '') || '') + '&url=' + __ll_e(__ll_d.getElementById('newsItemTitle').firstChild.getAttribute('href')) + '&via=' + __ll_e(__ll_d.referrer) + '&src=wk&v=1&fmt=js&t=' + (new Date().getTime());
}

if (do_save) {
__ll_e = document.createElement('script');
__ll_e.setAttribute('type', 'text/javascript');
__ll_e.setAttribute('charset', 'UTF-8');
__ll_e.setAttribute('src', __ll_u);

document.body.appendChild(__ll_e);
}

var __ll_ID = 'laterloop-overlay-shadow';
var shadow = document.getElementById(__ll_ID);
if (shadow) {shadow.parentNode.removeChild(shadow);}
shadow = document.createElement('div');
shadow.id = 'laterloop-overlay-shadow';
shadow.style.opacity = "0.0";
shadow.style.MozOpacity = shadow.style.opacity;
shadow.style.top="0";
shadow.style.left="0";
shadow.style.width="100%";
shadow.style.height="100%";
shadow.style.display="block";
shadow.style.position="fixed";
shadow.style.backgroundColor="#fff";
shadow.style.zIndex = "99997";
shadow.onclick=function() {this.style.display='none';};
document.body.appendChild(shadow);
function fadeIn(obj, max, current) {
if (!current) {
current = 0.1;
}
else {
current = Math.min(current+0.15, 1);
}
obj.style.opacity = current;
obj.style.MozOpacity = shadow.style.opacity;
if (current < max) {
setTimeout(function() {fadeIn(obj, max, current);}, 15);
}
else {
setTimeout(function() {document.__ll_elapsed=true;}, 500);
}
}
document.__ll_elapsed=false;
if (do_save && do_fade) {
fadeIn(shadow, 0.7);
}
if (!do_save) {
setTimeout(function() {
document.title = document.title.replace(/^\[(Saved|Saving...)\]\s/, '');
}, 500);
}
})();

Then save this bookmarklet to NNW's Scripts folder with a name ending in .js:
javascript:void((function(){var%20d=document;var%20h='file:///Users/andrew/';d._ll='KNsDvhqgrfcpJBmWtjfe';try{var%20e=d.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src',h+'ll.js');d.body.appendChild(e);}catch(x){e=encodeURIComponent;w=window;qs='&key='+d._ll+'&title='+e(d.title||'')+'&url='+e(d.getElementById('newsItemTitle').firstChild.getAttribute('href'))+'&via='+e(d.referrer)+'&fmt=html&src=wk&v=1&t='+(new%20Date().getTime());u=h+'/post/?'+qs;w.top.location.assign(u);return;}s='[Saving...]%20';d.title=s+d.title.replace(s,'');})());

You will need to replace file:///Users/andrew/ with the path to the directory in which you saved ll.js.

For this script to work, you will also need to select Enable JavaScript under NNW preferences > Browsing > News Items. The script should show up in the scripts menu, where you can click it to save the current article to LaterLoop (assuming you are logged in). To make this even more convenient, you can easily add a keyboard shortcut to this script. Go to System Preferences > Keyboard & Mouse > Keyboard Shortcuts, press the + button to add a new shortcut, select NetNewsWire as the application, type in the filename of your script as the Menu Title, and assign whatever keyboard shortcut you want. I assigned it to Cmd-1, which is the keyboard shortcut I use for the LaterLoop bookmarklet in Safari.

Now I can press Cmd-1, and the current article flashes to let me know it's been saved to LaterLoop.

Here's a brief video of it in action (this video would only play in Firefox for me).

You might be thinking, why couldn't I use this technique with Delicious or Instapaper (the other two services I've tried)? Well, the Delicious bookmarklet doesn't seem to do anything in NNW, and the Instapaper bookmarklet replaces the article's text with "Saved", then closes NNW. However, I'm sure there are other services out there that will work with the technique I've described, so if you are using another service you may want to try it out using your existing bookmarklet.

This system works very well, but the one other thing I would really like to be able to do would be to view my unread LaterLoop links in NNW. LaterLoop does in fact publish an RSS feed of your links, but they a.) Include links you've already read and b.) limit the number of links in your feed to 30.

As an aside, the NetNewsWire style you see in the video is called Bullit.

8 comments Tuesday, March 18, 2008

Larry from ScriptingForLawyers.com has submitted a much-improved version of the NetNewsWire to del.icio.us script. His version uses the cURL terminal command to post to del.icio.us in the background, so it works without the help of Safari or Firefox. It asks you for your username and password the first time you run the script, then stores it to a preference file thereafter. Furthermore, it includes error handling to alert you if your NetNewsWire headline did not post correctly.

Here's the improved script:


property usernamePasswordString : ""
property tagsString : ""

on run
checkUsernameAndPassword()
postToDelicious()
end run

on postToDelicious()
tell application "NetNewsWire"
if exists selectedHeadline then
set u to "\"?&url=" & (URL of selectedHeadline) & ¬
"&description=" & (title of selectedHeadline) & ¬
"&tags=" & tagsString & "\""
set curlStatement to "/usr/bin/curl -u " & usernamePasswordString & " -d " & u & " https://api.del.icio.us/v1/posts/add"
set retValue to do shell script curlStatement
if retValue contains "wrong" then
display dialog "Headline did not post to del.icio.us. Something went wrong."
end if
else
display dialog "Please select a headline to post to del.icio.us"
end if
end tell
end postToDelicious

on checkUsernameAndPassword()
-- Check to see if the file where our username and password are stored exists
try
do shell script "cd " & POSIX path of (path to preferences as text) & "; ls | grep com.larrystaton.toread.txt"
try
set prefFile to ((path to preferences as text) & "com.larrystaton.toread.txt")
open for access file prefFile with write permission
set prefs to read file prefFile using delimiter {return}
close access file prefFile
set usernamePasswordString to item 1 of prefs
set tagsString to item 2 of prefs
on error e
close access file prefFile
end try
on error
set username to text returned of (display dialog "Please enter your del.icio.us username" default answer "username")
set pass to text returned of (display dialog "Please enter your del.icio.us password" default answer "password")
set tags to text returned of (display dialog "Please enter any desired default tags" default answer "toread ")
try
set prefFile to ((path to preferences as text) & "com.larrystaton.toread.txt")
open for access file prefFile with write permission
set eof of file prefFile to 0
write username & ":" & pass & {return} & tags to file prefFile
close access file prefFile
on error e
close access file prefFile
end try
set usernamePasswordString to username & ":" & pass
set tagsString to tags & " "
end try
end checkUsernameAndPassword


[Update: Larry and I have improved the script even further to fix a bug with the preference file, and to add a prompt to ask you your desired default tags the first time the script is run. If you want to later change your username/password or default tags, just trash the preference file named com.larrystaton.toread.txt in your ~/Library/Preferences/ folder, and it will ask you again for this information the next time the script is run.]

[Update 2: As Mario pointed out in the comments, the script would get into trouble when the default tag was left completely blank (it would ask for your username/password/default tag every time). The new version of the script avoids this problem by inserting a space after the default tags. I simply changed set tagsString to tags to set tagsString to tags & " ".]

5 comments Saturday, March 15, 2008

[Update: Check out a much-improved version of this script submitted by Larry of ScriptingForLawyers.com.]

I've modified existing NetNewsWire to del.icio.us Applescripts to save the currently-selected news item to del.icio.us with the tag "toread". You can easily change this tag to whatever tag you use to mark items you wish to read later on.

The script works by running JavaScript in Safari that opens a pop-up window that sends your URL and tags to del.icio.us and then closes that window. Currently, I have the window set to stay open for 0.5 seconds (delay 0.5), but you can adjust this if it wasn't enough time.

To adjust the tags that are sent to del.icio.us, edit the line containing "&tags=toread " & (subject of selectedHeadline). You can set multiple preset tags by separating them with spaces. For instance, to add tags "readlater" and "for:user1234", change this line to "&tags=readlater for:user1234 " & (subject of selectedHeadline). If you don't want the subject(s) of the new item to be added to the tags, simply remove & (subject of selectedHeadline).

tell application "NetNewsWire"
set u to (title of selectedHeadline) & ¬
"&url=" & (URL of selectedHeadline) & ¬
"&tags=toread " & (subject of selectedHeadline)
end tell

tell application "Safari"
do JavaScript "javascript:void(open('https://api.del.icio.us/v1/posts/add?description=" & u & "','delicious','toolbar=no,width=150,height=100'));" in document 1
delay 0.5
close current tab of front window
end tell


I personally run this script using a Trigger in QuickSilver.

0 comments Tuesday, February 19, 2008

Here are some interesting links about the future of human-computer interfaces.

1 comments Wednesday, January 30, 2008


Here's a mockup of what a version of Firefox for the iPhone might look like. While Mozilla has not yet announced whether they will port this to the iPhone, they are working on a mobile version of Firefox for both touch-screen and regular smart phones. They have stated that they will be supporting Windows Mobile and Linux devices, and that "support for other Platforms may be added in the future." A working UI mockup of Mobile Firefox can be downloaded and run through Firefox.


It is pretty evident that the Mobile Firefox team was inspired by Mobile Safari on the iPhone in their UI design. An iPhone version of Firefox would bring two things to the iPhone: 1) Extensions such as Adblock and Greasemonkey, and 2) Support for XUL, which could be used to create web applications.

0 comments Sunday, January 27, 2008

Matt Tucker writes on Jivesoftware.com about using XMPP (also known as Jabber) for push-based cloud services. The idea is that, rather than having the client software poll the service at a regular interval, which wastes resources, the server will push updates to the client as they become available. While this has always been the desired way to update clients, with HTTP it is not easy to set a push system up. 

Using the XMPP protocol, originally developed for instant messaging, one could develop an e-mail client that is set up as a subscriber in an XMPP connection. The server would send new e-mails to the client as XML fragments in the data stream.

A number of XMPP-related projects are hosted at Ignite Realtime. These projects include OpenFire, an XMPP-based IM server, Spark, an XMPP-based IM client, the Smack API, a Java XMPP API, and the XIFF API, a Flash XMPP API. Java.net has an interesting write up (including examples) of Smack.