Reliably Open iTunes Library on a Shared Volume

0

I just mentioned that my wife switches between two different iTunes libraries, including one that lives on a shared volume on our home server. There’s a great tip on Stack Overflow for writing a script to automate that swap between iTunes libraries (rather than having to hold down option while iTunes loads and then click around to find the library you want). But it seemed like it might be nice to document for posterity the full script that we’ve built, since it handles not just the library swapping, but also the mounting of the shared volume as well.

This script takes a little prep work, both generating the library location property and storing the authentication information in the user keychain. The Stack Overflow tip explains the former, and the latter is as easy as connecting to the server and remembering to check the “Save Authentication” checkbox during the authentication process.

-- set server connection information here
property serverProtocol : "afp://"
property serverName : "your-server-name-here.local"
property volumeName : "shared-volume-name-here"
 
-- define the desired library location and save the current library location (http://stackoverflow.com/a/1693973/294171 explains exactly how to generate the appalling hexadecimal value for iTunesLibraryLocation below)
property iTunesLibraryLocation : ""
property libraryLocationPref : "com.apple.iTunes 'alis:1:iTunes Library Location'"
 
-- try to mount share from server
try
	-- authentication credentials stored in keychain
	mount volume (serverProtocol & serverName & "/" & volumeName)
on error
	-- if we can't mount the share, we're done
	display dialog "The shared volume “" & volumeName & "” on the server “" & serverName & "” could not be mounted, so the remote iTunes Library cannot be used. Please check that you are on the same network as “Leviathan” and try again later." buttons ("Le sigh") default button 1 giving up after 15
	return
end try
 
-- quit iTunes if it's running
tell application "System Events"
	if exists (application process "iTunes") then
		tell application "iTunes" to quit
	end if
end tell
 
-- set the desired library location
do shell script "defaults write " & libraryLocationPref & " " & quoted form of iTunesLibraryLocation
 
-- comment the above shell script and uncomment the one below to use the default iTunes Library
-- do shell script "defaults delete " & libraryLocationPref
 
-- (re)open iTunes
tell application "iTunes" to activate

iTunes Locked Disk Error

0

A bit of background: my wife has an iTunes library that is too large to fit comfortably on her MacBook Air (in all fairness: I have an iTunes library that is too large to fit on her MacBook Air, my MacBook Pro and several other laptops as well). She maintains a local library on her laptop for use at school (useful movies, songs, etc.) and stores her “real” library on our home server. Which involves a bit of fiddling to get it to work. The key issue is that she needs iTunes to load her library off of a shared disk. And, periodically (maybe every couple of months), something goes haywire and she gets this error:

The iTunes library Library file is locked, on a locked disk, or you do not have write permission for this file.

Needless to say, this is exasperating.

There are a number of suggested solutions out there, and I keep forgetting to bookmark “the one” that works. On my last search, I realized that this was because none of them are really the answer that works in our situation. Here’s what works (and I’m posting this as a note for self):

  1. Disconnect the laptop from the server (quitting iTunes first, of course).
  2. On the server, unset the nouchg flag (not 100% that this is necessary 100% of the time, but it’s necessary at least some of the time):
    sudo chflags -R nouchg <path to iTunes folder>
  3. Reboot the server.
  4. Reconnect from the laptop and rejoice.

At least, that’s what worked this evening, and it felt really familiar. (There’s an unspoken step 2a, of course: cancel the multi-hour process on the server that you had queued up moments before iTunes started misbehaving. Argh.)

Doubled Google Calendars in iCal

1

So many of these entries are really just an attempt to make sure that the next time I go searching for an answer to some question, by gum there will be a search result. That is: I write up things that I couldn’t find an easy answer to, so that someone else reaps the benefit of my suffering.

But, sometimes, it’s just about admitting that I’m dumb.

Case in point: I’ve been grousing on Twitter about a number of things in the past week, one of which was that, for much of the fall, many of my Google calendars have been showing up in iCal doubled. Every event shows up twice. Sometimes more than that, when Google has a hiccup. And birthdays from my contacts have shown up as many as 34 times — no joke: I counted. But the core problem has been that I’ve been seeing many of my Google calendars twice in iCal. It makes me feel busy, but otherwise it serves no purpose.

And then it hit me this evening, as I was looking at the list of calendars in iCal: with the launch of Mountain Lion, Apple revised how it handled Mail, Contacts & Calendars — so much so, in fact, that they created a separate prefpane for it. That connects to iCal, Mail and the Address Book pretty transparently. Before that upgrade, to see secondary Google calendars (the ones other than your primary calendar — a distinction about which I have some more grousing to do at a later date), you had to enable calendar delegates in the Accounts section of the iCal preferences. It was messy, and ugly (you had both the delegate and the calendar nested in the delegate… for each and every calendar). But it worked.

I never turned off the delegates when Apple upgraded to Mail, Contacts & Calendars. So I was seeing both the delegate calendar and the calendar associated with my Google account in Mail, Contacts & Calendars.

For dumb.

I just turned off delegates and everything got better. Except maybe those duplicated birthdays… we’ll see what happens with them.

Embed YouTube Playlist in IFRAME-unfriendly Blackboard 8

0

YouTube has changed their embed codes (several years ago) to IFRAMEs, replacing the old object embed codes. Turns out that on older web-based WYSIWYG-editors, such as Blackboard 8, the IFRAME embed codes get munged up, often with deleterious effects. In Blackboard, for example, you might lose the ability to see, edit or use a content area in which an IFRAME has been embedded. This. Is. Bad.

YouTube lets you switch to their old embed code for individual videos, but no so to embed a playlist. I wanted to embed a playlist, so I took a look at the object tag specs and the IFRAME embed code and came up with a simple script that generates an old-style object embed code for a YouTube playlist IFRAME embed code, thus:

Paste a YouTube playlist embed code below.

Moving iMovie ’11 Events and Projects to a Custom Location

0

I’m about to embark on a group video project in my New Media class. To that end, it’s a hassle when the video (and script!) exist only in the account of one of the group members. I saw one suggestion for how to store the iMovie events and projects on an external drive, which seemed deeply convoluted and, well… a hassle. I’m not interested in purchasing or setting up external drives, or in going through that rigamarole to set it up.

So, it occurred to me that /Users/Shared/ is a pretty fine place to store shared files. And that the modern Mac OS X seems to honor symlinks pretty regularly (something I use all the time to sync my life across machines using dropbox — symlinking whole directories to sync preferences, settings and documents that the developers haven’t — yet — moved to the cloud.)

It seems to work for iMovie as well. Here’s how I did it (stay tuned to see if it blows up on my students!):

  1. Trash the iMovie Events folder in the user’s Movies folder. (This assumes that this is, essentially, a clean install of iMovie — no previous events or projects to worry about. That’s my situation).
  2. Create a new iMovie Events folder in /Users/Shared/ (note that it is created there, not moved or copied there, so that it will inherit permissions from the Shared directory).
  3. Set the permissions on iMovie Events to let everyone read and write. I like the terminal for this:

    chmod -R a+rw /Users/Shared/iMovie\ Events
  4. In the terminal, create the symlink:

    ln -s /Users/Shared/iMovie\ Events ~/Movies/iMovie\ Events

    (Note that the space in “iMovie Events” needs to be escaped with a backslash!)

  5. In iMovie, create new projects on the hard drive (probably called Macintosh HD), rather than the user’s home folder. This will put the projects in /User/Shared/ (I didn’t know that until this experiment — cool!)

In my limited testing, this seems to work transparently. The biggest caveat is the permissions change. When creating events, iMovie seems to strip the write permissions off of the inherited permissions for the iMovie Events folder (but other users can still read and execute, which should be fine). Similarly, it’s possible that other users can only read (but not edit) the shared project.

We shall see.

Linking to a Cell in a Google Spreadsheet

1

Because I can’t stop playing with something that already works fine, I’ve continued to tweak my syllabus-generating spreadsheet. With the addition of an external script, I’m able to link directly to a specific cell in the spreadsheet — letting me share a link to my syllabi that takes people not just to the overall document, but to the current day (or the next day that’s closest to the current day) in the syllabus. The script could be used to link to any cell in any published Google Spreadsheet, with the caveat that if there are multiple cells with that match that value, the link will take you to the first appearance of the value in the spreadsheet.

$url = $_REQUEST["url"];
$key = $_REQUEST["key"];
$anchor = $_REQUEST["anchor"];
 
$html = file_get_contents($url);
$output = str_replace($key, "<a name="$anchor"></a>$key", $html);
$output = str_replace("href='/", "href='https://docs.google.com/", $output);
 
header("Content-Type: text/html");
echo $output;

This takes a GET URL of the format http://server/script?url=[url]&key=[key]&anchor=[anchor]#[anchor], where…

  • The URL is the URL of the published Google spreadsheet location.
  • The key is the text to search for in the spreadsheet (so you could link to anything in the published HTML, but it’s easiest to link to a unique value in a cell).
  • The anchor is the name of the HREF anchor you will be creating (note that you then need to, well… link to that anchor).
Enjoy. You can try it out on my server:
URL:
Key:
Anchor:

Nota Bene: You have to add your own link to the anchor — this is a quick, slapped-together connection to my script.

Update: I was sitting here staring at the script, trying to figure out why I hadn’t put the anchor tag around the key, and then I realized what’s going on. The key (on my spreadsheet) is formatted to be white text on a white background (Rothko-style, if you will). If it gets converted to an anchor, its styling is affected and (without more work in the script) it turns blue and underlined. Lame. So… the anchor goes before the key, so the key’s CSS style won’t be affected.

This is why you document your code. Even when it’s short.

Visual Homework Policy

1

Click to download a PDF of this. Feel free to reuse it — just let me know, especially if you make any particularly effective tweaks.

This policy has been gestating for some time, and I started to formulate it in conversation with one of my students who had had a brush with the academic dishonesty fairy. I presented it in class last week, and I realized that it is as good a representation as I have of my homework policy. I’m not really interested in coming up with a suitably punitive formula for docking grades for lateness, and I don’t particularly care about negotiating reasonable extensions. Mostly, like my students, I just don’t want to be bothered. But, by golly, there are things that bother me, and it would be good to steer clear of them. And it’s worth knowing how they rank in my worldview. And this expresses it.

Better not to do your work than to cheat or plagiarize to finish your work. Better to ask for an extension at the last minute than to just not do the work. But noticeably better to ask for the extension in a timely manner.

I’m pretty sure that this both made sense to and stuck with my ninth graders.

Better Ways to Share Documents (than Email Attachments)

2

I had hoped that someone else would have put together a handy flyer to explain better options for sharing files than sending email attachments. But in a casual search of the web, none came up. This is my initial pass at the problem of presenting the Web 2.0 and the cloud to folks who are comfortable with email, but who don’t feel confident in their use of other technologies.

The first pass is truly aimed at providing a flyer that could be tacked up next to someone’s monitor.

I made a second version, which I posted to Google Docs, so that the links are clickable as well.

If you’d like to examine the assumptions and reasoning behind this, I have a flowchart that I felt… might not be as helpful in conveying these ideas.

For what it’s worth, when I was discussing the response to this broadsheet (broadside?) among the folks at school, my wife asked me if I sent this as an attachment.

She’s a funny one.

Transmogrifying those Google Reader JSON dumps into something useful

9

For the last few years (my JSON feed tells me: since 2008), I have been tagging and annotating articles of interest as they passed before my eyes in Google Reader. This served a two-fold purpose:

  1. I could find them again later, easily, because they were tagged and annotated.
  2. I could share an RSS feed with those annotations to particular interest groups that I worked with (e.g. anything tagged “for robotics” would show up on my advanced computer science class’ portal page, or anything tagged “for academic computing” would show up on my school home page).

This was a great way to share (and manage) resources. Granted, much of what passed before my eyes in Google Reader was trivial and not of lasting value, but this filtering allowed me to hang on to at least a few gems for future reference.

And then Google Reader got the Google+ treatment and sharing items broke. But you could download a JSON dump of all the items that you had ever shared. It wasn’t entirely clear what you could do with this JSON dump, but… there it was. And then: I realized that all of my other information is stashed on my web server (and that I have become increasingly distrustful of relying on cloud services to maintain my data and workflows — e.g. my weekly backup of all my Google Docs… just in case).

Wouldn’t it be handy to import that JSON feed into a new blog on my server? So I wrote a PHP script that converts (at least my) Google Reader JSON dump into an XML file that WordPress can import as a list of posts. With the tags and annotations converted over. In fact, with all of the data in the JSON dump embedded in the XML file (although WordPress doesn’t read all of it).

This comes with a few caveats:

  • For items that came from blogs with a full feed, the result is a republication of the original post — which feels ethically dubious to me. (I have made my new blog of Google Reader shared items private, so that I have the data but I’m not sharing it with the world).
  • I’ve made guesses as to how to treat some of Google’s data. Reasoned, educated guesses, but guesses nonetheless. For example, I’m not super-clear on which dates in the file correspond with what events — does a publication date refer to when the item was shared or the original post was posted?
  • I’ve added in some arbitrary (and therefore, ideally, eventually, configurable) WordPress tags to make the import go more smoothly. Where I have done that, I mark it in the script as a TODO item. (And, in truth, I didn’t really test to see if all of these items were necessary.)
  • The original authors of the posts are transfered to the XML file, which means that when the actual import into WordPress is done, you will have the option to either laboriously create a new user for each distinct author or simply revert authorship to the currently logged-in WordPress user. It doesn’t seem like WordPress has a format for exporting or importing users (or, at least, my cursory search didn’t find it). Clearly an ancillary SQL query could be generated that pre-populated the WordPress database with the users that the XML file refers to. But I haven’t bothered to do that.
  • You’ll need your own PHP-compatible webserver to run the script, since I have been quick and dirty and simply imported the JSON file from and exported the XML file to the script’s local directory. And I have no interest in setting up my world-facing webserver to take the traffic hit of processing other people’s multi-megabyte JSON dumps.
With that said, here is the script, as it stands this morning.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**********************************************************************
 * Google Reader to Wordpress
 *
 * 2011-11-27
 * Seth Battis (seth@battis.net)
 * 
 * This script takes the output of Google Reader's JSON export of
 * shared items and converts it into an XML file that can be imported
 * into a Wordpress blog as posts. All of the data in the original JSON
 * file is preserved in the XML file, either by transfering it to
 * an appropriate format (e.g. Google Reader categories are converted
 * to WordPress post tags) or simply as an additional XML tag (e.g. the
 * Google Reader commentInfo metadata for recent shared items). In
 * situations where actual data has to be converted to make it readable
 * for WordPress, the original data is included as the JSON attribute
 * of that tag (e.g. timestamps and categories).
 *
 * As currently written, the script looks in its local directory for
 * Google Reader "shared-items.json" file and generates a matching
 * "shared-items.xml" file, also in its local directory.
 *
 * There are a number of potentially configurable (i.e. arbitrary)
 * values marked as TODO.
 *
 * Caveat emptor: this has been tested against my ~1000 item Google
 * Reader shared items feed and on my WordPress 3.2.1 site. I would
 * presume that it should work fairly well for others, but make no
 * guarantees!
 *********************************************************************/
 
/* returns a Wordpress slug-version of the given text (only
   alphanumeric characters and dashes) */
function sluggify($text)
{
	return preg_replace("|[^a-z0-9]+|", "-", strtolower($text));
}
 
/* SimpleXML doesn't really support namespaces unless you force it */
$xml = '<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:wp="http://wordpress.org/export/1.1/"
></rss>';
$rss = new SimpleXMLElement($xml);
$namespaces = $rss->getDocNamespaces(true);
 
/* load the Google Reader JSON file */
$file = file_get_contents("shared-items.json");
$json = json_decode($file, true);
 
/* Wordpress will choke if our post names aren't unique, so we track
   them separately */
$post_names = array();
 
/* header information describing the file itself */
$channel = $rss->addChild("channel");
$channel->addAttribute("direction", $json["direction"]);
$channel->addAttribute("id", $json["id"]);
$channel->addAttribute("self", $json["self"][0]["href"]);
$channel->addAttribute("author", $json["author"]);
$channel->addChild("title", $json["title"]);
$channel->addChild("link");
$channel->addChild("description");
$pubDate = $channel->addChild("pubDate", gmdate("D, j M Y G:i:s O", $json["updated"]));
$pubDate->addAttribute("json", $json["updated"]);
$channel->addChild("language");
$channel->addChild("wxr_version", "1.1", $namespaces["wp"]);
 
/* run through the list of items and add them to the XML */
foreach ($json["items"] as $item)
{
	$rssItem = $channel->addChild("item");
 
	/* a bunch of Google Reader-specific metadata */
	if (isset($item["isReadStateLocked"]))
	{
		$rssItem->addAttribute("isReadStateLocked", $item["isReadStateLocked"]);
	}
	$rssItem->addAttribute("crawlTimeMsec", $item["crawlTimeMsec"]);
	$rssItem->addAttribute("timestampUsec", $item["timestampUsec"]);
	$rssItem->addAttribute("id", $item["id"]);
	if (isset($item["commentInfo"]))
	{
		while (list($commentInfoKey, $commentInfoValue) = each($item["commentInfo"]))
		{
			$commentInfo = $rssItem->addChild("commentInfo", $commentInfoKey);
			$commentInfo->addAttribute("permalinkUrl", $commentInfoValue["permalinkUrl"]);
			$commentInfo->addAttribute("commentState", $commentInfoValue["commentState"]);
		}
	}
 
	/* annoyingly, not every item has its content in the content
	   element -- sometimes it's in the summary element (and once in a
	   while, it's just not there). I think this is an artifact of how
	   the original RSS feeds were constructed. I think. */
	if (isset($item["content"]))
	{
		$content = $item["content"]["content"];
	}
	else if (isset($item["summary"]["content"]))
	{
		$content = $item["summary"]["content"];
	}
	else
	{
		$content = "";
	}
 
	/* sometimes items don't even have titles */
	if (isset($item["title"]))
	{
		$rssItem->addChild("title", $item["title"]);
	}
 
	/* most items store the original linkback information in the
	   alternate element -- Wordpress won't honor this link tag when
	   it's imported (i.e. it won' treat it like the Daring Fireball
	   feed), so I have embedded a more descriptive linkback after the
	   annotations at the start of the content, using some information
	   from the origin element. The linkback is in the
	   "google-reader-alternate-href" div (for easy CSS-wrangling!) */
	if (isset($item["alternate"]))
	{
		$rssItem->addChild("link", htmlentities($item["alternate"][0]["href"], ENT_COMPAT, "UTF-8"));
		$content = htmlspecialchars("<div class=\"google-reader-alternate-href\"><p>Originally posted at <a href=\"{$item["alternate"][0]["href"]}\">{$item["origin"]["title"]}</a></p></div>", ENT_COMPAT, "UTF-8") . $content;
	}
 
	/* I haven't bothered to figure out if the dates are really GMT or
	   localized -- GMT was an easier assumption to make */
	$pubDate = $rssItem->addChild("pubDate", gmdate("D, j M Y G:i:s O", $item["published"]));
	$pubDate->addAttribute("json", $item["published"]);
 
	/* not every item has an a author, either -- again, an artifact of
	   the original RSS feeds */
	if (isset($item["author"]))
	{
		$rssItem->addChild("creator", $item["author"], $namespaces["dc"]);
	}
 
	/* annotations were tricky -- I have added them as their own XML
	   tags _and_ inserted them within a "google-reader-annotation" div
	   at the top of the post content (to match the original format on-
	   screen). All of the original data is preserved in the XML tag,
	   with an ID that matches the embedded div ID. */
	foreach($item["annotations"] as $annotation)
	{
		$annotationHTML = htmlentities("<div id=\"" . md5($annotation["content"] . $annotation["author"]) . "\" class=\"google-reader-annotation\"><blockquote><p>{$annotation["content"]}</p><p class=\"author\">{$annotation["author"]}</p></blockquote></div>", ENT_COMPAT, "UTF-8");
		$content = $annotationHTML . $content;
		$rssAnnotation = $rssItem->addChild("annotation", $annotation["content"]);
		$rssAnnotation->addAttribute("id", md5($annotation["content"] . $annotation["author"]));
		$rssAnnotation->addAttribute("author", $annotation["author"]);
		$rssAnnotation->addAttribute("userId", $annotation["userId"]);
		$rssAnnotation->addAttribute("profileId", $annotation["profileId"]);
		$rssAnnotation->addAttribute("profileCardParams", $annotation["profileCardParams"]);
	}
 
	/* again, sometimes content is in content, sometimes it's in the
	   summary element */
	$rssContent = $rssItem->addChild("encoded", $content, $namespaces["content"]);
	if (isset($item["content"]))
	{
		$rssContent->addAttribute("direction", $item["content"]["direction"]);
	}
	if (isset($item["summary"]))
	{
		$excerpt = $rssItem->addChild("encoded", $item["summary"]["content"], $namespaces["excerpt"]);
		$excerpt->addAttribute("direction", $item["summary"]["direction"]);
	}
 
	/* more Google reader metadata, this time about the original feed
	   that the item came from -- which is used above to format the
	   linkback that is embedded a the start of the content */
	$origin = $rssItem->addChild("origin");
	$origin->addAttribute("streamId", $item["origin"]["streamId"]);
	$origin->addAttribute("title", $item["origin"]["title"]);
	$origin->addAttribute("htmlUrl", $item["origin"]["htmlUrl"]);
 
	/* it's not clear to me whether the published or modified date is
	   when the original post was published or when the item <span class="hiddenGrammarError" pre="item ">was
	   shared</span> -- I think when published refers to when it was shared. */
	$postDate = $rssItem->addChild("post_date", date("Y-m-d G:i:s", $item["published"]), $namespaces["wp"]);
	$postDate->addAttribute("json", $item["published"]);
	$rssItem->addChild("comment_status", "open", $namespaces["wp"]);	// TODO make configurable
	$rssItem->addChild("ping_status", "open", $namespaces["wp"]);		// TODO make configurable
 
	/* make a Wordpress friendly title slug for the post */
	if (isset($item["title"]))
	{
		$slug = sluggify($item["title"]);
	}
	else
	{
		/* if no title, generate the slug from the timestamp */
		$slug = date("Y-m-d-G-i-s", $item["published"]);
	}
 
	/* make sure that our slug  is unique -- add a counter to the end
	   if it is not, and track those counter values in $post_names[] */
	if (isset($post_names[$slug]))
	{
		$post_names[$slug]++;
		$slug .= "-" . $post_names[$slug];
	}
	else
	{
		$post_names[$slug] = 0;
	}
	$rssItem->addChild("post_name", $slug, $namespaces["wp"]);
 
	/* more Wordpress metadata -- all of which could be tweaked */
	$rssItem->addChild("status", "publish", $namespaces["wp"]);	// TODO make configurable
	$rssItem->addchild("post_parent", 0, $namespaces["wp"]);	// TODO make configurable
	$rssItem->addChild("menu_order", 0, $namespaces["wp"]);		// TODO make configurable
	$rssItem->addChild("post_type", "post", $namespaces["wp"]);	// TODO make configurable
	$rssItem->addChild("post_password", "", $namespaces["wp"]);	// TODO make configurable
	$rssItem->addChild("is_sticky", 0, $namespaces["wp"]);		// TODO make configurable
 
	/* convert categories to post tags -- nota bene that Google Reader
	   has conflated the reader's categories with the original post's
	   tags, creating a... mish-mash. */
	foreach($item["categories"] as $category)
	{
		if (!preg_match("|.*/com\.google/.*|", $category))
		{
			$cleanCategory = $category;
			$cleanCategory = preg_replace("|user/\d+/label/(.*)|", "$1", $cleanCategory);
			$rssCategory = $rssItem->addChild("category", htmlentities($cleanCategory, ENT_COMPAT, "UTF-8"));
			$rssCategory->addAttribute("domain", "post_tag");
			$rssCategory->addAttribute("nicename", sluggify($cleanCategory));
			$rssCategory->addAttribute("json", $category);
		}
	}
 
	/* add comments -- note that for privacy reasons, while the
	   commenter's metadata is added as an XML tag, it is not embedded
	   in the Wordpress-readable wp:comment tags */
	foreach($item["comments"] as $comment)
	{
		$rssComment = $rssItem->addChild("comment", "", $namespaces["wp"]);
		$rssComment->addAttribute("id", $comment["id"]);
		$commentContent = $rssComment->addChild("comment_content", $comment["htmlContent"], $namespaces["wp"]);
		$commentContent->addAttribute("plainContent", $comment["plainContent"]);
		$author = $rssComment->addChild("comment_author", $comment["author"], $namespaces["wp"]);
		$author->addAttribute("userId", $comment["userId"]);
		$author->addAttribute("profileId", $comment["profileId"]);
		$author->addAttribute("profileCardParams", $comment["profileCardParams"]);
		$author->addAttribute("venueStreamid", $comment["venueStreamId"]);
		$commentDate = $rssComment->AddChild("comment_date", $comment["createdTime"], $namespaces["wp"]);
		$commentDate->addAttribute("modifiedTime", $comment["modifiedTime"]);
		$rssComment->addAttribute("isSpam", $comment["isSpam"]);
	}
}
 
/* dump the converted XML out as a file */
header ("Content-type: text/xml");
echo $rss->asXML();
file_put_contents("shared-items.xml", $rss->asXML());

Publishing a FirstClass Calendar to Google Calendar (or anywhere else)

2

As noted earlier, there is a slick trick for taking a publicly accessible calendar in FirstClass and generating an iCalendar feed. Also noted earlier, the big problem with this feed is that it doesn’t contain timezone information, which makes some calendar systems (most notably Google Calendar) assume that everything is happening at Greenwich Mean Time. Which it usually isn’t. And I have written a PHP script that adds Pacific Timezone information to the iCalendar feed.

Let’s put all this together and take a current FirstClass calendar, make it readable from the web, feed it through the script and then add the result to your calendar program of choice.

  1. Right-click (or control-click, on a Mac) on the calendar in question and Add to Desktop. A second calendar icon will appear, possibly named with the name of whoever’s calendar it is. Possibly not. FirstClass is a mystery.
  2. Drag the new calendar into your Web Publishing folder (on some versions, Web Publishing may be called Home Page Folder — why is this? FirstClass is a mystery.)
  3. At this point you’re faced with a choice: either blithely disregard security, rely on security through obscurity, or be ready to generate a somewhat more aggravating URL to be more (but still not fully) secure.
    1. Disregard security: leave the calendar named whatever it’s currently named. You need to change the permissions (right-click/control-click and choose Permissions) so that All Users has Schedule+Details permissions on the calendar. This will change permissions for not just the copy in the Web Publishing folder, but also for the original calendar — since the “copy” in Web Publishing is just an alias to the original anyway.
    2. Security through obscurity: rename the calendar something else (I usually do this, and use a password generating application to give me a random collection of letters and numbers — e.g. a2612GhxU). Change permissions as described in 3(a) above.
    3. Better security: follow the directions here for generating your URL. Don’t tinker with permissions.
  4. Point a web browser at calendar in your Web Publishing folder, add the iCalendar feed get parameters, and copy that new URL to the clipboard.
  5. Point your web browser your copy of the time zone script and paste the URL you just copied into the Calendar URL field and click Generate.
  6. Copy the new URL that appears below. You can paste that URL into whatever calendaring system you want (that can subscribe to iCalendar feeds).
    1. In Google Calendar, you would Add a new calendar by URL and paste in your URL. (caveat: Google doesn’t seem to be too fantastic about actually updating iCalendar feeds — they allege that this is a sporadic issue, but I have experienced it as more prevalent than sporadic).
    2. In iCal, you would choose Subscribe… from the Calendar menu and paste in your URL.
    3. You could also paste this URL (via some contortions — e.g. email it to yourself and copy-paste from that) into a phone calendar app.
Go to Top