I was doing something like this with Groovy and Cocoa. You need to add
/System/Library/Java to your CLASSPATH before running this. Here is a
link to a Mac OS X 10.3.9 executable you can use instead of downloading
the whole distribution of groovy: http://homepage.mac.com/spullara/groovy-jsr-02-SNAPSHOT-mac
I suggest you put it in /usr/bin/groovy so you can execute scripts
easily (remember to chmod +x it).
class PropertyListCategory {
static Object get(NSDictionary dictionary, String key) {
return dictionary.objectForKey(key);
}
static Object getAt(NSArray array, int i) {
return array.objectAtIndex(i);
}
static void each(NSArray array, Closure closure) {
for (i in 0..array.count()-1) {
closure.call(array[i]);
}
}
}
filename =
"${System.getProperty("user.home")}/Library/Safari/Bookmarks.plist";
data = new NSData(new File(filename));
errorString = new String[1];
format = new int[1];
plist = NSPropertyListSerialization.propertyListFromData(data,
NSPropertyListSerialization.PropertyListImmutable, format,
errorString);
if (errorString[0]) {
println "Error: ${errorString[0]}";
System.exit(1);
}
def getURLs(NSDictionary dict, list) {
if (dict.Children != null) getURLs(dict.Children, list);
if (dict.URIDictionary != null) {
list.add([title:dict.URIDictionary.title,
url:dict.URLString]);
}
}
def getURLs(NSDictionary dict) {
use (PropertyListCategory.class) {
def list = [];
getURLs(dict, list);
}
return list;
}
println getURLs(plist);
On Apr 23, 2005, at 7:32 AM, Bill Tschumy wrote:
I did find a (sort of) solution to my problem. First, I didn't make
clear that the Safari Bookmarks.plist is in binary format. That's
what made it hard to read from Java.
However I found the "plutil" utility in /usr/bin that will convert
plists between binary and XML formats. So now I copy the
Bookmarks.plist to /tmp, use Runtime's exec() to run plutil on it, and
then I can use the SAX classes to easily extract the URLs from the
resulting XML.
On Apr 22, 2005, at 3:27 PM, Bill Tschumy wrote:
Does anyone have some code to share for reading Safari's bookmarks
file which is in .plist format? I need to extract all the URLs in
there.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden