Open selected file in same instance/window of SPEK

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Fram
Posts: 46
Joined: Mon Aug 01, 2016 6:37 am

Open selected file in same instance/window of SPEK

Post by Fram »

Hi guys! I'm really struggling with this. Maybe someone could help me :(

I want to open files using this sript in the same instance of Spek (same window) (http://spek.cc/)
At this moment it will open in another window every time. The only way is to drag and drop in the same window.

This is the script:

Code: Select all

' A simple script that shows how to open a selected track in another application.
' In this case it is Spek (expected to be in C:\Program Files (x86)\Spek\spek.exe).

Const SpekPath = "C:\Program Files (x86)\Spek\spek.exe"

Sub OpenInSpek 
  ' Define variables
  Dim WShell, Command, NPSong

  ' Get list of selected tracks from MediaMonkey
  Set NPSong = SDB.Player.CurrentSong 

  ' Prepare WScript.Shell object, which can be used for execution of applications
  Set WShell = CreateObject("WScript.Shell") 

  If Not NPSong is Nothing Then
	Command = Chr(34) & SpekPath & Chr(34) & " " & Chr(34) & NPSong.Path & Chr(34) 
  End If

   ' And execute the command
  WShell.Run Command, 1, 0 
End Sub 
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Open selected file in same instance/window of SPEK

Post by Peke »

I do not see that spek detect already started and it should be made within app at least for windows :( VBS is Limited in process detection. See

Code: Select all

Function IsProcessRunning( strComputer, strProcess )
    Dim Process, strObject
    IsProcessRunning = False
    strObject   = "winmgmts://" & strComputer
    For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
    If UCase( Process.name ) = UCase( strProcess ) Then
        IsProcessRunning = True
        Exit Function
    End If
    Next
End Function
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Fram
Posts: 46
Joined: Mon Aug 01, 2016 6:37 am

Re: Open selected file in same instance/window of SPEK

Post by Fram »

You are right! That's also what I was thinking about.
I'm curious if I can make this script to work like this: if i select a track, that track to automatically open in Spek (even if I select it by a simple click or directional (up&down) arrows).
At this moment it will open the selected track only when i press a keyboard shortcut (Ctrl+S for eg.)
You can help me with this or I have to create another post with this issue ? :D
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Open selected file in same instance/window of SPEK

Post by Peke »

Hi,
From what i tried you should close/terminate existing process and start new one :( SPEK limitation

See more info at https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Fram
Posts: 46
Joined: Mon Aug 01, 2016 6:37 am

Re: Open selected file in same instance/window of SPEK

Post by Fram »

i found something on internet about how to run only one instance of an application here: https://stackoverflow.com/questions/419 ... pplication , but i have difficulties to implement this for SPEK release here : https://github.com/withmorten/spek/releases
You seem to be more experienced with programming than I do. (I have not coded for about 4 years now: D). Maybe you want to try or help me with this code. Thank you :)
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Open selected file in same instance/window of SPEK

Post by Peke »

Hi,
I would not bother with SPEK itself, but rather just control when to start and when to Close it and start new one.

here is the code for notepad:

Code: Select all

dim S, X
Sub LaunchNotepad()
  Set S = CreateObject("WScript.Shell")
  Set X = S.Exec("Notepad.exe")
End Sub
Sub QuitNotepad()
  If X.Status = 0 Then X.Terminate()
  Set X = Nothing
  Set S = Nothing
End Sub
Call LaunchNotepad
WScript.Sleep 10000
Call QuitNotepad
Try to use http://www.mediamonkey.com/wiki/index.p ... n::Objects in your script to save X, S or see https://msdn.microsoft.com/en-us/librar ... 90%29.aspx to set X, S as VAR that will be passed on next Script start. There are few scripts that already do that.

Also you can use parameters also https://msdn.microsoft.com/en-us/subscr ... 84%29.aspx
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Fram
Posts: 46
Joined: Mon Aug 01, 2016 6:37 am

Re: Open selected file in same instance/window of SPEK

Post by Fram »

Thanks a lot Peke!
I really appreciate the help given but the information presented is too much for me at this moment. Maybe i will return someday when i'll have more time to digest all this information. :D
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Open selected file in same instance/window of SPEK

Post by Peke »

Hi,
OK, it seams to me fairly simple to change and add as 90% of code you already have here and should work after Copy/Paste and little modification., I also agree when all thrown at once it looks like complicated ;)
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Open selected file in same instance/window of SPEK

Post by Peke »

Hi,
As I thought it it was easy :)

Here is your script http://www.happymonkeying.com/plugin.php?q=300107

Only thing is that it was not meant for me to make it :(
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Fram
Posts: 46
Joined: Mon Aug 01, 2016 6:37 am

Re: Open selected file in same instance/window of SPEK

Post by Fram »

Thank you Peke!!
i got an error at running the script: Error #424 - Microsoft VBScript runtime error. Object required: '[string: "SPEK"]'. File: "C:\Users\...\Local\Temp'MediaMonkey\install.vbs", Line:5, Column:4." & "Error: SPEK not installed".
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Open selected file in same instance/window of SPEK

Post by Peke »

Updated :( Sorry

Note: I installed SPEK in c:\SPEK change path in runspek.vbs
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
popsmike
Posts: 174
Joined: Thu Oct 05, 2006 11:02 am
Location: Hull,UK

Re: Open selected file in same instance/window of SPEK

Post by popsmike »

Peke wrote:Updated :( Sorry

Note: I installed SPEK in c:\SPEK change path in runspek.vbs
I addressed it slightly different as i'm using it as a portable install.

I Extracted the Spek folder into my plugins folder then addressed in runspek.vbs as "Plugins\Spek\Spek.exe"
Windows 10 Pro x64 2TB USB3 External Hdd with Quad Core 3600Mhz CPU and 10GB Ram
MM 4.1.21.1871 Portable on External Hdd
TESTING MM 5.0.0.2113
Numerous Addons
User Since 2006 (Lifetime License) since 2012
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Open selected file in same instance/window of SPEK

Post by Peke »

Hi,
So all is OK now. From my tests MMIP installs on portable also.

Are you satisfied with performance?
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Fram
Posts: 46
Joined: Mon Aug 01, 2016 6:37 am

Re: Open selected file in same instance/window of SPEK

Post by Fram »

The script run perfectly now, you made a really good job :D. Thank you again!
Now I'm wondering if it can be made to keep the original position and size of the window.
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Open selected file in same instance/window of SPEK

Post by Peke »

No unfortunately, that is controlled by SPEk and Windows.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Post Reply