Save this script as an application, then navigate to the application and show package contents. Add the following to the main
Monday, March 5, 2012
Launching magnet links in Transmission remotely
This applescript will allow you to click magnet links in your browser to launch them in an instance of Transmission running on a remote server instead of a local instance. Be sure to fill in the user/pass and the address of your torrent box.
Save this script as an application, then navigate to the application and show package contents. Add the following to the main in info.plist:
Save this script as an application, then navigate to the application and show package contents. Add the following to the main
Wednesday, January 14, 2009
Change audio devices via shell script
I searched for a long time for a way to activate Soundflower as part of a script, but I couldn't find any way to do so, short of opening system preferences and using UI scripting to control the settings.
There had to be a better way.
I found SoundSource, but I couldn't find any way to activate it from applescript, even with UI scripting. I asked the developers about scriptability, and after a few emails back and forth, they decided to release the source, which I used to build audiodevice.
Audiodevice
Source
This the basic functionality of SoundSource with a quick and dirty command line interface slapped on. Type "audiodevice help" for usage information. Since I got my Airport express, I haven't had much use for my Soundflower script, but I still regularly use it in conjunction with Proxi to activate my bluetooth headset from the keyboard.
There had to be a better way.
I found SoundSource, but I couldn't find any way to activate it from applescript, even with UI scripting. I asked the developers about scriptability, and after a few emails back and forth, they decided to release the source, which I used to build audiodevice.
Audiodevice
Source
This the basic functionality of SoundSource with a quick and dirty command line interface slapped on. Type "audiodevice help" for usage information. Since I got my Airport express, I haven't had much use for my Soundflower script, but I still regularly use it in conjunction with Proxi to activate my bluetooth headset from the keyboard.
Wednesday, January 2, 2008
Directory listing as podcast
Here is a quick and dirty (as always) php script to turn a directory listing into an rss 2.0 feed with enclosures, suitable for use with a podcast client. Just drop a copy of this script into the directory and point your feed reader at it. The script automatically hides itself in the listing.
PHP:
PHP:
<?php
$link = 'http://'.$_SERVER['SERVER_NAME'].preg_replace('/\/[^\/]+\.[^\/]+$/', '/', $_SERVER['REQUEST_URI']);
$items = preg_replace('/\s+->\s.*$/','', explode("\n", `ls -FlopTt`));
$items = preg_grep('/('.preg_replace('/.*\//', '', $_SERVER['PHP_SELF']).')$|^$|^total/', $items, PREG_GREP_INVERT);
header('Content-type: application/rss+xml; charset=utf-8');
echo '<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>'.$_SERVER['SERVER_NAME'].preg_replace('/\/[^\/]+\.[^\/]+$/', '/', $_SERVER['REQUEST_URI']).'</title>
<link>'.$link.'</link>
<description>Contents of '.$link.'</description>
<language>en-us</language>
';
foreach ($items as $value) echo '<item>
<title>'.preg_replace('/^(\S+\s+){10}/', '', $value).'</title>
<description>'.$value.'</description>
<enclosure url="'.$link.rawurlencode(preg_replace('/^(\S+\s+){10}/', '', $value)).'" length="'.preg_replace('/^(\S+\s+){5}((\S+){1}).*/', '\2', $value).'" type="'.mime_content_type(preg_replace('/^(\S+\s+){10}/', '', $value)).'" />
<guid>'.$link.rawurlencode(preg_replace('/^(\S+\s+){10}/', '', $value)).'</guid>
<pubDate>'.gmdate('D, d M Y G:i:s', strtotime(preg_replace('/^(\S+\s+){6}((\S+\s+){4}).*/', '\2', $value))).' GMT</pubDate>
</item>
';
echo '</channel>
</rss>';
?>
Thursday, December 6, 2007
Start torrent downloads from an iPhone
I have a server that I use for, among other things, downloading files with bittorrent. I usually start these torrents by downloading them on my primary computer and then dropping them onto an alias to my server's torrents folder, which my bittorrent client (Transmission) monitors so that it can start the torrents automatically. I occasionally wanted to use my iPod Touch to start these torrents, but Mobile Safari refuses to download torrent files.
My solution was to use javascript to alter the torrent link to send its url to my server for download rather than trying to open it. A php script on the server could then download that url to the torrents folder. With both scripts in place and the permissions of the torrents folder modified to allow apache to write files, all I have to do is run the javascript as a bookmarklet before clicking the torrent link, and click the link to download the torrent file. The modified link will pass this url to the script to download it on the server.
Bookmarklet: torrent
PHP:
Modifications required:
My solution was to use javascript to alter the torrent link to send its url to my server for download rather than trying to open it. A php script on the server could then download that url to the torrents folder. With both scripts in place and the permissions of the torrents folder modified to allow apache to write files, all I have to do is run the javascript as a bookmarklet before clicking the torrent link, and click the link to download the torrent file. The modified link will pass this url to the script to download it on the server.
Bookmarklet: torrent
PHP:
<?php
if (!($_SERVER['PHP_AUTH_USER'] == "username" && $_SERVER['PHP_AUTH_PW'] == "password")) {
header('WWW-Authenticate: Basic realm="torrent"');
header('HTTP/1.0 401 Unauthorized');
} else {
passthru('curl -H "Referer: '.$_SERVER['$HTTP_REFERER'].'" -H "User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-us) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10" -o /path/to/monitored/torrents/folder/remote.torrent "'.$_SERVER['QUERY_STRING'].'"');
}
?><script type="text/javascript">history.back()</script>
Modifications required:
- script url in bookmarklet
- username in php script
- password in php script
- torrents folder path in php script
Labels:
bittorrent,
iPhone/iPod Touch,
javascript,
php
Who's hacks?
I already have a blog, but I wanted a place to share some of my hacks and the little bits of code I'm always writing, which may or may not be useful to anyone else. Because this is so different from the subjects of my existing blog, I decided to start a separate one. I plan to use this space to post new hacks as I create them, as well as to post some of older ones when the mood strikes. I hope this will motivate me to clean up some of my code, but don't be surprised to see a lot of one-liners, few if any comments, and stuff that barely works. Everything it offered as-is, and I don't promise to respond to questions about implementation or modification, although I probably will in most cases.
Subscribe to:
Posts (Atom)