GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Play music albums when their folders are double-clicked

vbscript
scripting
events

#1

Overview

This script makes it so you can double-click music albums to listen to them.

Here's a short video showing what the script does and how it is configured. (The video is narrated, with optional subtitles.)

The script works by changing what double-click does when in thumbnails mode for specific folders (which you can configure).

To play the album, the script searches the for an .m3u playlist within the folder you double-clicked.

Since this only affects thumbnails mode, the script can be left enabled and your album folders can still be entered and managed in details mode.

Double-clicks will enter folders normally if you are not in thumbnails mode, or if you are not in one of the configured folders, or if no playlist is found within the folder you double-click.

Installation:

  • Go to Preferences / Toolbars / Scripts.
  • If you had the original v1.0 installed, select it and delete it.
  • Download AlbumDoubleClick.vbs.txt (3.39 KB)
  • Drag AlbumDoubleClick.vbs.txt to the list of scripts.

Usage:

Once installed, select the script in Preferences and click the Configure button. You'll see a list of script settings, although there is only one called AlbumFolders for this script.

Double-click the AlbumFolders line to edit that setting.

By default, it's set to these two folders:

Those are the folders where the script will change what double-click does. You can add or remove folders from the list as you wish. As you can see from the defaults, using aliases like /profile is allowed.

Click OK in both dialogs, and don't forget to click OK or Apply in the main Preferences dialog (your script config changes won't be saved until you do that).

History:

v1.2 (20-Jan-2016):

  • Now looks for both .m3u and .m3u8 files, to support Unicode playlists.

v1.1 (01-Oct-2015):

  • Script will no longer affect middle-mouse double-clicks and double-clicks while holding Shift, Ctrl or Alt.
    (Change requires Opus 11.16.1 or above.)

v1.0 (14-Feb-2014):

  • Initial version.

The script itself:

If you just want to use the script, the AlbumDoubleClick.vbs.txt download above is all you need.

The script code is reproduced here to make it easier for people browsing the forum for scripting techniques.

Option Explicit

' Album Double-Click
' (c) 2014-2016 Leo Davidson
' 
' This is a script for Directory Opus.
' See http://www.gpsoft.com.au/redirect.asp?page=scripts for development information.
'
' This script makes it so double-clicking a music album folder thumbnail will play the album
' instead of entering the folder.
'
' It works by changing what double-click does when in thumbnails mode for specific folders
' (which you can configure). To play the album, it searches the for an .m3u playlist within
' the folder you double-clicked.
'
' Since this only affects thumbnails mode, the script can be left enabled and your album
' folders can still be managed in details mode normally, while Opus turns into a music
' selection UI when you switch to thumbnails mode in the chosen folders.

' Called by Directory Opus to initialize the script
Function OnInit(initData)
	' Provide basic information about the Script
	initData.name = "Album Double-Click"
	initData.version = "1.2"
	initData.desc = "Double-click music album thumbnails to play them"
	initData.copyright = "(c) 2014-2016 Leo Davidson"
	initData.default_enable = true

	Dim vecDefFolders
	Set vecDefFolders = DOpus.NewVector
	' Default folders / example config.
	vecDefFolders.push_back("/profile\Music")
	vecDefFolders.push_back("D:\Audio\Music Albums")

	initData.config.AlbumFolders = vecDefFolders
	initData.config_desc = DOpus.Create.Map("AlbumFolders", "List of folders the script should affect.")
End Function

' Helper Function
Function IsPathInVector(fsu, path, vecFolders)

	IsPathInVector = False
	
	' Resolve aliases, libraries, etc. to their real/absolute paths.
	path = fsu.Resolve(path)

	Dim testPath
	
	For Each testPath in vecFolders
	
		If (fsu.ComparePath(path, fsu.Resolve(testPath))) Then
			IsPathInVector = True
			Exit Function
		End If
	Next

End Function

' Called on double-click.
Function OnDoubleClick(doubleClickData)

	' Don't change anything if we're not in thumbnails mode.

	If (doubleClickData.tab.format.view <> "thumbnails") Then
		Exit Function
	End If

	' Only affect left button double-clicks, with no qualifiers held down.

	If (doubleClickData.mouse <> "left" Or doubleClickData.qualifiers <> "none") Then
		Exit Function
	End If

	' Cache the FSUtil object, for efficiency.
	Dim fsu
	Set fsu = DOpus.FSUtil

	' Don't change anything if we're not in one of the configured folders.

	If (Not IsPathInVector(fsu, doubleClickData.tab.Path, Script.config.AlbumFolders)) Then
		Exit Function
	End If

	' Don't change anything if the double-clicked item is not a folder.

	If (Not doubleClickData.item.is_dir) Then
		Exit Function
	End If

	' Look for a .M3U or .M3U8 file below the folder.

	Dim folderEnum
	Set folderEnum = fsu.ReadDir(doubleClickData.item, false)
	
	Dim childItem
	Do While (Not folderEnum.Complete)

		Set childItem = folderEnum.Next

		' Check for a .m3u extension. This also has the effect of ignoring folders,
		' since folders always have an empty extension property (even if they
		' have a name containing a dot), so we don't have to check that separately.
		If (childItem.ext = ".m3u" or childItem.ext = ".m3u8") Then

			' Launch the .m3u file we found.
			DOpus.NewCommand.RunCommand """" & childItem & """"

			' Prevent the standard double-click action.
			OnDoubleClick = True

			Exit Function
		End If
	Loop

End Function

Multiline or JSON ScriptConfig type
Symbolic links & Junctions issues
DO11 OnDoubleClick = 'true'; not working with JScript
#2

Leo, please share your Foobar config. Thank you!


#3

I used "export theme" in Foobar to make this, which hopefully has what you want (zipped so the forum accepts it):
leo_foobar_theme.zip (2.41 KB)


#4

Excellent, thanks...


#5

Thanks for sharing your Foobar theme... it looks great.

Unfortunately I can't get this script to work. I have viewed you video (several times) and closely followed all steps but when I double click on a folder, the folder opens rather than launching the m3u file.

For clarification, the script appears in the preferences dialog, I have edited the paths, for simplicity, to [b]c:\mp3test[/b] and deleted all existing paths. The mp3test folder has several folders which contain mp3 files, coverart.jpg and a .m3u playlist. By default the m3u file opens with Foobar2000 so no problems there.

Any obvious reasons why it won't work for me? I can upload a video if it helps.


#6

Are you in thumbnails mode when you double-click?


#7

Yes but that wasn't the issue. I upgraded from beta 6 to 7 and it is now working. Should it have worked with beta 6? If so, then a reboot must have sorted it out. Thanks for the script, I love it.


#8

I don't have m3u files in all my album folders, so I modified the script slightly. My version launches foobar with the double clicked album without needing an m3u file.



AlbumDoubleClick.osp (1.43 KB)


#9

I have my music organized as Artist\Album\*.mp3
Is there a way to enable the script for all Artists without adding them manually to the config ?

thanks,
t.


#10

Um...what am I doing wrong? All I get when the script is dragged to the Toolbar/Scripts pane in settings is 'AlbumDoubleClick' with a checkbox. All the About/Configure/Edit buttons are greyed out. Thanks.


#11

Extract the .vbs file from AlbumDoubleClick.ocs and use that file instead. You may have to rename the .ocs file to .zip.


#12

You shouldn't need to do that for the Configure button, at least.


#13

@FunTanK:
Go to the parent folder of your artists folders, select all artist folders and copy the paths to the clipboard with Ctrl+Shift+C. Now go to the Scripts page in Prefs, select the script and click on Configure. Doubleclick the single entry at the top and you can paste the clipboard content to the list.


#14

@kundal
thanks for the suggestion. My problem is not adding lots of folders to the config once but to do this everytime I add music to my libary.
Dopus users always try do it future-proof :smiley:


#15

@FunTanK:

When do you want the script to do somethign, and what do you want it to do?

i.e.

  • Script to do ~something when you enter one of the Artist folders, or still just one of the album folders?
  • If Artist folder, what do you want Opus to launch in foobar? All songs under that Artist folder? M3u from the Artist folder itself? M3u's from the album folders UNDER the Artist?
  • If still just one of the album folders, I suppose you have m3u's in each album folder you want the script to load, or just all the files?

Depending on what you want, might need to change the trigger or how the script treats the path that you enter in the config dialog.

@blogward:

What Beta release are you running? Upgrade to current in any case just to be sure... but all the buttons EXCEPT for the Configure button SHOULD be greyed out.


#16

^^ this

thanks for your time!

t.


#17

And...


#18

As my english is not the best I try to clarify what I want with an example:

C:\Music\New Model Army\Carnival
C:\Music\New Model Army\Eight
C:\Music\New Model Army\High
C:\Music\New Model Army\Impurity

In all 4 (sub)folders there is a .m3u playlist.

Now I want to add C:\Music\New Model Army\ to the config. When I double-click on one of the Album Folder the given m3u is launched.

thanks,
t.


#19

I added a new script command AlbumDoubleclick to this script that enables/disables the functions of the script depending on the state of the global variable adc. With this you can create a button that toggles the doubleclick action. To see the current state reflected by the toolbar icon it's necessary to add a second line @toggle:if $glob!:adc to the button code after you dropped the command from the command list so it looks like this:

Button Code

@toggle:if $glob!:adc
AlbumDoubleclick

Album Double-Click with Toggle-Script Command

Option Explicit

' Album Double-Click
' (c) 2014 Leo Davidson
' 
' This is a script for Directory Opus.
' See http://www.gpsoft.com.au/redirect.asp?page=scripts for development information.
'
' This script makes it so double-clicking a music album folder thumbnail will play the album
' instead of entering the folder.
'
' It works by changing what double-click does when in thumbnails mode for specific folders
' (which you can configure). To play the album, it searches the for an .m3u playlist within
' the folder you double-clicked.
'
' Since this only affects thumbnails mode, the script can be left enabled and your album
' folders can still be managed in details mode normally, while Opus turns into a music
' selection UI when you switch to thumbnails mode in the chosen folders.

' Called by Directory Opus to initialize the script
Function OnInit(initData)
	' Provide basic information about the Script
	initData.name = "Album Double-Click"
	initData.version = "1.0"
	initData.desc = "Double-click music album thumbnails to play them"
	initData.copyright = "(c) 2014 Leo Davidson"
	initData.default_enable = true

	Dim cmd
	Set cmd = initData.AddCommand
	cmd.name = "AlbumDoubleclick"
	cmd.method = "OnAlbumDoubleclick"
	cmd.desc = "Double-click music album thumbnails to play them"
	cmd.label = "Album Double-Click"
	cmd.icon = "togglesounds"

	Dim vecDefFolders
	Set vecDefFolders = DOpus.NewVector
	' Default folders / example config.
	vecDefFolders.push_back("/profile\Music")
	vecDefFolders.push_back("D:\Audio\Music Albums")

	initData.config.AlbumFolders = vecDefFolders
End Function


' Helper Function
Function IsPathInVector(fsu, path, vecFolders)

If (DOpus.vars.Exists("adc")) = False Then
	Exit Function
End If

	IsPathInVector = False
	
	' Resolve aliases, libraries, etc. to their real/absolute paths.
	path = fsu.Resolve(path)

	Dim testPath
	
	For Each testPath in vecFolders
	
		If (fsu.ComparePath(path, fsu.Resolve(testPath))) Then
			IsPathInVector = True
			Exit Function
		End If
	Next

End Function

' Opus calls this whenever something is double-clicked
Function OnDoubleClick(doubleClickData)

If (DOpus.vars.Exists("adc")) = False Then
	Exit Function
End If

	' Don't change anything if we're not in thumbnails mode.

	If (doubleClickData.tab.format.view <> "thumbnails") Then
		Exit Function
	End If

	' Cache the FSUtil object, for efficiency.
	Dim fsu
	Set fsu = DOpus.FSUtil

	' Don't change anything if we're not in one of the configured folders.

	If (Not IsPathInVector(fsu, doubleClickData.tab.Path, Script.config.AlbumFolders)) Then
		Exit Function
	End If

	' Don't change anything if the double-clicked item is not a folder.

	' Temporary workaround for issue in Opus 11 Beta 7: doubleClickData.item.is_dir
	' is an integer (1 or 0) rather than a boolean (True or False), which will be fixed
	' in Beta 8. This checks both.
	If (doubleClickData.item.is_dir <> 1 And doubleClickData.item.is_dir <> True) Then
		Exit Function
	End If

	' Look for a .M3U file below the folder.

	Dim folderEnum
	Set folderEnum = fsu.ReadDir(doubleClickData.item, false)
	
	Dim childItem
	Do While (Not folderEnum.Complete)

		Set childItem = folderEnum.Next

		' Check for a .m3u extension. This also has the effect of ignoring folders,
		' since folders always have an empty extension property (even if they
		' have a name containing a dot), so we don't have to check that separately.
		If (childItem.ext = ".m3u") Then

			' Launch the .m3u file we found.
			DOpus.NewCommand.RunCommand """" & childItem & """"

			' Prevent the standard double-click action.
			OnDoubleClick = True

			Exit Function
		End If
	Loop

End Function

' Implement the AlbumDoubleclick command
Function OnAlbumDoubleclick(ClickData)

Dim var
If DOpus.vars.Exists ("adc") = False Then
	DOpus.vars.Set "adc", 1
	Set Var = DOpus.vars ("adc")
	Var.persist = True
Else
	DOpus.vars.Delete ("adc")	
End If

ClickData.Func.Command.UpdateToggle

End Function

I think the method I used here is generally useful for ScriptAddIns to be able to switch them On/Off. Integrating this into all scripts would enable us to have a menu where we can easily switch all scripts On/Off without having to do this in preferences. It would be great if we also could toggle the icon dependend on the variable state.
Maybe GPSoft will provide an easier way to toggle Script-AddIns On/Off even in Prefs in a future version. :wink:


#20

I think tbone opened up a thread looking to do something with @icon based on environment variables...