I’m wondering if it’s possible to get a filename from the console using some kind of shell script. My script simply launches a file from a playlist of a non-scriptable application (mplayer) by simulating a keyboard stroke, so I can’t get the name of the launched file from the app itself. Is this possible?
UNTESTED
mplayer shows a list of movies-to-play. So, if you use System Events to simulate a keystroke, you could also use System Events to retrieve the name of the file from the table view… :?:
tell application "System Events"
tell process "MPlayer OS X 2"
set move1Name to value of text field 1 of row 1 of table 1 of scroll area 1 of window "MPlayer OS X"
end tell
end tell
thanks for your reply, I really appreciate it. Actually I’m simulating the keystroke with Salling Clicker. But even if I use System Events this code doesn’t seem to work. The variable doesn’t return anything. Also, what I wanted wasn’t really the name of the first item of the playlist, but the name of the launched item (could be any file in the playlist). Any other ideas?
Have you installed the latest beta System Events, aka UI-Scripting?
Anyway, you can try this, which attempts to get the latest-played movie, which should be also the current playing-in-progress:
--> read 20000 last bytes of the console log
set last20000bytes to (do shell script "tail -c 20000 /private/var/tmp/console.log")
set AppleScript's text item delimiters to return & "Playing "
set playedFiles to rest of (last20000bytes's text items)
set AppleScript's text item delimiters to {""}
--> we have now a list of latest played files
--> we are interested in the last one
set ourFile to paragraph 1 of (playedFiles's item -1)
--> eg: "/Users/username/Desktop/musicVideos/scorpions__still_loving_you_live_by_makkor.mpg"
--> extract file name or whatever you want