 |
 |
What's up with lsof?
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Hey,
I'm trying to write a script that will tell me what music, of any format, is being played on a computer. I'm using lsof, and iTunes to play the music (aac, and mp3 files) and lsof seems to randomly show the files. I'd like to do
For instance, if I do "lsof | grep iTunes" while playing Cake's "Comfort Eagle", then I get:
Code:
iTunes 507 gtaubman 16r VREG 14,5 5348066 934753 /Users/gtaubman/Music/iTunes/iTunes Music/Cake/Comfort Eagle/05 comfort eagle.mp3
But some other mp3s don't show up. Also, no aac (or m4a as iTunes calls them) show up ever. Is there any way to make this more predictable? Thanks!
gabe
PS, on a side note, what does this mean?:
Code:
27 [Optimus@~]gt % man grep
sh: fork: Resource temporarily unavailable
/usr/bin/groff:fatal error: fork: Resource temporarily unavailable
Error executing formatting or display command.
system command exited with status 32768
No manual entry for grep
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status:
Offline
|
|
My guess is they don't appear because the files aren't open.
iTunes will typically open a file and read it into ram, playing it from ram and leaving the file closed. Since the file isn't open, lsof doesn't see it. You're probably seeing it sometimes since you're occassionally running the script while iTunes is still reading in the file.
Surprisingly enough, given that iTunes is an Apple app, AppleScript is the easiest way to go with this:
Code:
osascript -e 'tell application "iTunes" to get location of current track'
-->alias Macintosh HD:Users:me:Music:iTunes:iTunes Music:Mazzy Star:So Tonight That I Might See:Fade Into You.m4p
You can get any properties of the track in this way:
If you just wanted the name of the song (not its path):
Code:
osascript -e 'tell application "iTunes" to get name of the current track'
Or how long this track has been playing:
Code:
osascript -e 'tell application "iTunes" to get player position'
length of the current track:
Code:
osascript -e 'tell application "iTunes" to get duration of the current track'
Play with the last two numbers and you can calculate when the next track will start, and so on.
|
|
Gods don't kill people - people with Gods kill people.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status:
Offline
|
|
Originally posted by Zimwy:
PS, on a side note, what does this mean?:
Code:
27 [Optimus@~]gt % man grep
sh: fork: Resource temporarily unavailable
/usr/bin/groff:fatal error: fork: Resource temporarily unavailable
Error executing formatting or display command.
system command exited with status 32768
No manual entry for grep
This means that the shell wasn't able to fork a new process to run man. This could be from a number of factors including insufficient ram, too many files open, or a corrupt file.
Does it work sometimes and not others? what about after a fresh boot/login?
|
|
Gods don't kill people - people with Gods kill people.
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Wow, thanks. All that itunes info is great. The only problem is that it's not always itunes that will be playing these files. Sometimes they'll be being streamed from a gnump3d server, or possibly any other form of streaming server. Any ideas for that?
Gabe
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Actually, and doing that osascript doesn't work either. I made sure I escaped the quotes and everything, but it still returns nothing. I echo the command it's executing, and then the results, and I get a perfect osascript line, and then NOTHING. If I do it in the terminal, it works fine. Grrrr. I've tried exec, shell_exec, and ``s.
gabe
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status:
Offline
|
|
Originally posted by Zimwy:
Actually, and doing that osascript doesn't work either. I made sure I escaped the quotes and everything, but it still returns nothing. I echo the command it's executing, and then the results, and I get a perfect osascript line, and then NOTHING. If I do it in the terminal, it works fine. Grrrr. I've tried exec, shell_exec, and ``s. 
gabe
Clearly if it works in the terminal, the script is valid and works.
How are you trying to call the script?
|
|
Gods don't kill people - people with Gods kill people.
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Here's what I do:
[PHP]
$toExec = "osascript -e 'tell application \"iTunes\" to get name of the current track'";
$mp3s = `$toExec`;
echo ($mp3s);
[/PHP]
I've also tried: $mp3s = exec($toExec);
and $mp3s = shell_exec($toExec);
and neither work.
The thing is that if I do
[PHP]
$toExec = "uptime";
$uptime = `$toExec`;
echo ($uptime);
[/php]
then it works fine. Very frustrating.
gabe
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Feb 2003
Location: Sundsvall, Sweden
Status:
Offline
|
|
Originally posted by Zimwy:
Here's what I do:
[PHP]
$toExec = "osascript -e 'tell application \"iTunes\" to get name of the current track'";
$mp3s = `$toExec`;
echo ($mp3s);
[/PHP]
I've also tried: $mp3s = exec($toExec);
and $mp3s = shell_exec($toExec);
and neither work.
The thing is that if I do
[PHP]
$toExec = "uptime";
$uptime = `$toExec`;
echo ($uptime);
[/php]
then it works fine. Very frustrating.
gabe
i would say it doesnt work cus, httpd is running under another user than ure logged in as.
osascript cant send events to apps thats running under a different user than itself, unless u put sudo infront of it,
but for that to work ud have to add the user "www" to /etc/sudoers
but dont do that, cus of big security issues.
however what u could do(i think) is add this to /etc/sudoers
www ALL = NOPASSWD: /usr/bin/osascript
that will allow the www user run osascript as root, without typing a password...
im not a security expert of any kind, so dont blame me if this causes any trouble, im sure there are other ways to do it tho...
good luck
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|