I'd like to be able to launch a video player (VLC, SMPlayer) via Terminal, using some command like resume_media and then it will automatically find the most recently played media file (.mkv, mp4 etc.) in a folder and resume the playback from where it was stopped.

How can I achieve this?

  • 1
    @Tim: No, that question is totally different from this one. That one talks about resuming playback in a particular video file, but this one is about finding the most recently played video file, and then resume from where playback was stopped. – Joseph John Dec 5 '14 at 17:47
  • Cool, undone that! Hmm you could possibly write a script for that... – Tim Dec 5 '14 at 17:48

If you have Zeitgeist daemon running on your system, it should save some helpful info to ~/.local/share/recently-used.xbel file. Zeitgeist monitors access to files on disk, so it should know your most recently played video file. Unfortunately the files are not sorted by file access, but the database contains that information too, so you can grep all data you need and then look for most recently file in a loop.

I just wrote a Bash script to find the most recently played file with "video/*" MIME type and play it using SMPlayer (but you can use any video player, of course).


# get list of files with MIME type "video/*"
video_files_list=$(grep -B3 "<mime:mime-type type=\"video/" ~/.local/share/recently-used.xbel | grep "modified=")

while read -r line
    # extract modification time (last access to file)
    date_line=$(echo "$line" | cut -d'"' -f6)
    if [ "$date_recent" \< "$date_line" ]
        file_name=$(echo "$line" | cut -d'"' -f2)
done <<< "$video_files_list"

# file name is encoded like URL, use Python to decode it
file_name=$(python -c "import sys, urllib as ul; print ul.unquote_plus(\"$file_name\")")

# play video
smplayer "$file_name"

Save it to file, add permission to execute and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.