PDA

View Full Version : New to Mac - Simple bash script



StratosFeaR
31st January 2008, 02:52 PM
Trying to do something fairly simple.

I've got a headless windows download box with a torrent hot folder. Drop a torrent file in there and it starts downloading.

In the past I set up Firefox to automatically execute .torrent files with a bat file that would move the torrent file to the hot folder on the download box.

Now i'm trying to do this on OSX (10.5) with Firefox and running into issues.

I've made a file called 'torrent.command' (i tried torrent.sh but had the same issue)

with the following content


#!/bin/bash
mv $1 "/Volumes/win/Hot Folder"

Now I've told firefox to open any .torrent files with that command file but it fails to download and complains saying it (firefox) can't open the file because of an unknown error.

It's probably an obvious error but i'm only 20 hours into my first real play with OSX (yay for scrapping my pc and getting a macbook)

Any help would be appreciated.

Cheers.

Currawong
31st January 2008, 03:29 PM
In Terminal.app type:

chmod +x (then drag the script to the Terminal window and hit return)

then see if it works.

coljac
31st January 2008, 04:09 PM
Trying to do something fairly simple.

I've got a headless windows download box with a torrent hot folder. Drop a torrent file in there and it starts downloading.

In the past I set up Firefox to automatically execute .torrent files with a bat file that would move the torrent file to the hot folder on the download box.

Now i'm trying to do this on OSX (10.5) with Firefox and running into issues.

I've made a file called 'torrent.command' (i tried torrent.sh but had the same issue)

with the following content


#!/bin/bash
mv $1 "/Volumes/win/Hot Folder"

Now I've told firefox to open any .torrent files with that command file but it fails to download and complains saying it (firefox) can't open the file because of an unknown error.

It's probably an obvious error but i'm only 20 hours into my first real play with OSX (yay for scrapping my pc and getting a macbook)

Any help would be appreciated.

Cheers.

Firstly, I want to be your friend, because that's a cool setup, exactly the sort of thing I would waste a weekend setting up. :D Welcome to MacLand.

I've got another solution for you - have a folder action (http://www.apple.com/pro/tips/folderactions.html) or a launchd (http://www.macgeekery.com/tips/all_about_launchd_items_and_how_to_make_one_yourse lf) script monitor your firefox download folder, like you have on the linux box. I highly recommend Lingon (http://lingon.sourceforge.net/) for this - with a gui you can give it a bash script to run on a folder change, the rest should be easy from there. Just have it scp and rm any .torrent files it sees.

StratosFeaR
31st January 2008, 05:10 PM
Thanks guys. Folder Actions are nice :)


on adding folder items to this_folder after receiving these_items
tell application "Finder"
repeat with added_file in these_items
if name of added_file ends with ".torrent" then
set Size_1 to 0
set Size_2 to 1
repeat while Size_2 ≠ Size_1
set Size_1 to Size_2
delay 3
set Size_2 to size of (info for added_file)
end repeat
move added_file to folder "win:Hot Folder:"
delete added_file
end if
end repeat
end tell
end adding folder items to

EDIT: Made a change to the code so it won't move it until the file is complete.