Reply
Thread Tools
Posts: 5 | Thanked: 0 times | Joined on Sep 2008
#1
hello, i would like to automate some tasks on my n800 (OS2008) : play a mp3 file during a preset time (e.g. 60') and then shutdown the tablet. The aim is of course to simulate a clock radio's 'sleep' function. Alternatively, rather than a preset time, the shutdown could occur when the mp3 file has been completely played. Any suggestions ?
 
Benson's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#2
Code:
mpg321 file.mp3; run-standalone.sh dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.req_shutdown
 
Posts: 5 | Thanked: 0 times | Joined on Sep 2008
#3
would it be possible to write a script (python ?) that
1) start mplayer (or another player) with the adequate options to play a mp3 file and then exit
2) init shutdown of the tablet (or at least enter in sleep mode)
 
Posts: 5 | Thanked: 0 times | Joined on Sep 2008
#4
thanks benson, (ignore my 2nd post, i was writing it before i got your answer);
however, i'm a complete newbie in linux; i guess that i have to enter those instructions in a command line ? And how to record these instructions in a batch (script) ?

Last edited by jpg; 2008-09-20 at 18:57.
 
Benson's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#5
OK, no need for python, and same as above except use mplayer instead of mpg321.

That's a line of text you can enter in the shell; to save it in a file as a shell script, prepend a shebang line like this:
Code:
#!/bin/sh
mplayer file.mp3; run-standalone.sh dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.req_shutdown
The shebang tells the OS what to execute this script with; /bin/sh is the shell. You'll need to make the script executable with
Code:
chmod +x scriptfile
Then you'll be able to run it with
Code:
./scriptfile
or you can add it to e.g. Personal Menu, or make a .desktop file to get it in the Apps menu.

(And as for sleep mode, the tablet doesn't really have a sleep mode; when the processor has nothing to do, it stops, and once the screen backlight times out, it draws almost no power. An N800 in this state (fully powered on, and left to sit) will last about a month, and will wake up instantly on touching the the screen. This is the recommended state to leave the tablet in, as booting actually consumes significant power, several days' worth at idle.)
 

The Following User Says Thank You to Benson For This Useful Post:
Benson's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#6
Ah, just saw your third post, but I hope I've adequately answered it...
 
Posts: 5 | Thanked: 0 times | Joined on Sep 2008
#7
sorry, i don't get it, you seems to presume i'm much more knowledgeable than i am (moreover english is not my 1st langage);
This is what i understand : i have to create a script, that's the role of the #!/bin/sh line ?
The 2nd line (mplayer ...) is the content of the script; but how do i save it as a script ?
I tried to enter #!/bin/sh in xterm, i don't see any 'reply' from the os; in fact it's the 1st time i really use xterm (i downloaded it just for sake of curiosity).

So perhaps the best thing i can do is start reading a tutorial about linux command line ...

Anyway, as you told me that the tablet automatically enters in a very 'frugal' mode when it has nothing to do, then shutting down the tablet is not really necessary, as i will use it as a 'clock radio' every night. So the problem is much simpler : i just have to start mplayer with the name of a mp3 file, at the end of the file, mplayer ends, and after a minute or 2, the tablet enters in quasi 'sleep mode'. I will try that.

Last edited by jpg; 2008-09-20 at 19:36.
 
Benson's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#8
Okay, a little detail on shells, scripts, and shebangs. Some of this you don't need right now, and don't worry if it doesn't completely make sense, but having heard it once should help you not get confused in some particularly annoying ways that many newbs do.
The UNIX way is, among other things, to have the command interpeter (a shell) separated from the core OS (the kernel); in fact, the shell is just another process, on the same level as the database, document typesetter, or other apps. Another aspect of the UNIX way is that all* resources are abstracted as files; files that are abstractions rather than actual data on a disk are called special files, and mainly live in /dev/, though they can be created anywhere. One example of a resource that's a file is a system console (maybe /dev/tty0); writing data to it displays on the console's screen, and reading data from it gets data from the console's keyboard.** These two characteristics mean that a shell operates by reading commands from a file and writing output to a file. (These can be the same file, but don't have to be.) Normally, using a machine from the console, the shell would be reading from /dev/tty0, and writing to /dev/tty0, so you type commands and see the output.

But if you don't like typing commands repeatedly, you can put some commands you like into a file, and do something like
Code:
sh <mycommandfile
This starts a new shell process (we can do that, because it's separated from the kernel), but it will read from mycommandfile instead of the keyboard.

Since UNIX hackers are lazy (or efficient, depending how you look at it), it was desirable to add some way of executing such a script directly. Initially, this was implemented by the shell; if you tried executing something that wasn't a known binary format, the shell would try to interpret it as commands itself. That's not a clean solution, though, as the file may not be shell commands (maybe commands for some other process), there are different shells with different command sets, and it doesn't work if you try executing it any other way but a shell.

So Ritchie added the #! mechanism to the UNIX 8 shell (and it was carried from there to BSD 4.0, and eventually SVR4 (I think), and of course Linux), to let a script specify the right interpreter, and since this is in the kernel, scripts (shell, perl, or whatever) can be treated basically the same as binary executables. Adding the #! isn't strictly necessary, as a shell script without it will still run from the shell as in UNIX 7, but it can't hurt, because eve n on systems not supporting shebangs (or when typing it into the shell, as you did), starting with a # makes the line be treated as a comment, and ignored. That's why the chosen sequence started with a #.

*Actually, not quite all, but we're talking about the UNIX way, not about UNIX. It's a lot closer to all than other OSes.
**The tty stands for teletype, which were the canonical console devices. tty is now used generically for any character special file. An xterm uses a pty (psuedo-tty), which is a pair of special files with no associated hardware resource; the xterm uses one file, and the shell uses the other exactly the same as if it were a serial port, console, or other tty.
As for what you need to do:
  • Make sure you're running OS2008, and probably the latest version (Diablo); you said you downloaded xterm, but it comes preinstalled in all OS2008 versions.
  • Open a file in a text editor and paste those lines into it. (The text editor vi comes with the tablet, but it's not particularly friendly. You'll probably want to install joe, nano, or some graphical editor. You have to be very careful if you use Notes, as it uses both plaintext and an HTML subset, and it's hard to be sure you're actually saving as text.)
 

The Following User Says Thank You to Benson For This Useful Post:
Posts: 5 | Thanked: 0 times | Joined on Sep 2008
#9
Many thanks for such 'dedication' for helping beginners.

The instructions you gave at the end of your previous post are much clearer, in fact i just have to create a text file, as i would do for creating a batch for windows.

Concerning xterm, i have the memory of having downloaded it, but it was surely when i was using os2007 some months ago; now i'm using os2008, so surely as you said xterm came with it.

I realise that there is great potential in being able to control the tablet from a command line; but I won't abuse from your time, if i want to investigate more deeply the subject, i will have to spend some time in learning unix basics.

And for my initial question (just play a mp3 then 'sleep'), problem is solved, as you said the tablet will automatically enter in quasi sleep mode when it has nothing to do. So no need to shut down. I feel a bit shameful to discover that only now, as i own my tablet since several months.

Last edited by jpg; 2008-09-21 at 06:38.
 
Reply


 
Forum Jump


All times are GMT. The time now is 03:52.