Open selected file in same instance/window of SPEK

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

Moderator: Gurus

Open selected file in same instance/window of SPEK

Postby Fram » Thu Jul 20, 2017 7:54 am

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
Fram
 
Posts: 20
Joined: Mon Aug 01, 2016 6:37 am

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

Postby Peke » Thu Jul 27, 2017 11:46 am

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,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10492
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

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

Postby Fram » Thu Sep 21, 2017 5:33 am

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
Fram
 
Posts: 20
Joined: Mon Aug 01, 2016 6:37 am

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

Postby Peke » Fri Sep 22, 2017 6:24 pm

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,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10492
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

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

Postby Fram » Wed Sep 27, 2017 4:25 am

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 :)
Fram
 
Posts: 20
Joined: Mon Aug 01, 2016 6:37 am

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

Postby Peke » Wed Sep 27, 2017 7:58 pm

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,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10492
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

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

Postby Fram » Thu Sep 28, 2017 5:45 am

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
Fram
 
Posts: 20
Joined: Mon Aug 01, 2016 6:37 am

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

Postby Peke » Thu Sep 28, 2017 8:37 am

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,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10492
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

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

Postby Peke » Thu Sep 28, 2017 10:25 am

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,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10492
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

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

Postby Fram » Tue Oct 03, 2017 7:01 am

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".
Fram
 
Posts: 20
Joined: Mon Aug 01, 2016 6:37 am

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

Postby Peke » Tue Oct 03, 2017 10:57 am

Updated :( Sorry

Note: I installed SPEK in c:\SPEK change path in runspek.vbs
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10492
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

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

Postby popsmike » Wed Oct 04, 2017 2:45 pm

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.15.1821 Portable on External Hdd
TESTING MM 5.0.0.2057
Numerous Addons
User Since 2006 (Lifetime License) since 2012
popsmike
 
Posts: 150
Joined: Thu Oct 05, 2006 11:02 am
Location: Hull,UK

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

Postby Peke » Wed Oct 04, 2017 5:46 pm

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

Are you satisfied with performance?
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10492
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

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

Postby Fram » Thu Oct 05, 2017 12:09 am

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.
Fram
 
Posts: 20
Joined: Mon Aug 01, 2016 6:37 am

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

Postby Peke » Thu Oct 05, 2017 8:08 am

No unfortunately, that is controlled by SPEk and Windows.
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10492
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

Next

Return to MediaMonkey 4 Addons developer forum

Who is online

Users browsing this forum: No registered users and 3 guests