Wanted: Sample scripts to cannibalize

Page 1 of 6 123 ... LastLast

  1. Posts : 720
    Win10 x64 Pro - 2 desktops, 2 laptops
       #1

    Wanted: Sample scripts to cannibalize


    I need to create a simple (I hope) script and have it working in less than 2 weeks. I'm not terribly proficient in any scripting language but am comfortable with .bat scripts and can stumble around in .vbs (given good samples). PowersShell might as well be Sanskrit. (I know I should learn PS but the learning curve is too long for this project.) JavaScript is another possibility. I've never used it, but I suspect it has a shorter learning curve than PS.

    The script needs to
    1. Present and process a file selection display of some sort. It would be ideal if it looked and felt similar to File Explorer but I'll accept anything that works.
    2. Open a file, read the data, and close the file.
    3. Modify the data read in step 2. The data will be a number of file paths - local, not UNCs.
    4. Open a file, write data (overwriting, if it already exists), and close the file.
      (I assume steps 2, 3, and 4 will happen concurrently.)
    5. Invoke a program (as though using "Open With" in File Explorer) to process the data written in step 4.

    I'm sort of envisioning this as an HTA, but I could use anything that works.

    I'm not worried about steps 2, 3, and 4; I'm sure I can get that part to work. I have no idea how to do step 1 although I'm sure it can be done. A lot of applications do that.

    I am most worried about step 5. I have no idea how "Open With" passes the selected file's path to the program or the program accesses that data. (Is it just like calling a program with an argument?)

    I will be writing this on Win10 21H1 (build 19043.1348) but it will have to run on some very old computers running Win7, on newer computers running Win10, and probably eventually on Win11.

    Are there some scripts around that I can use as models?
      My Computer


  2. Posts : 744
    Windows 10/11
       #2

    Yes, an HTA could be a good option. You can use VBScript or JScript code within an HTA. I'll follow up with some examples in the next day or two, but a bit more info about what you're trying to accomplish would be helpful. The requirements, as stated, don't really say what problem you're trying to solve.
      My Computer


  3. Posts : 720
    Win10 x64 Pro - 2 desktops, 2 laptops
    Thread Starter
       #3

    What I am trying to accomplish will, I fear, sound trivial, but will save me (and others, perhaps) some frustration.

    Some background ... to keep my description from seeming meaningless:
    I belong to a folkdance group that uses MediaMonkey as a player and organizing tool for its music library. We have multiple potable implementations of Mediamonkey, each with its own database and copy of our library. We (mostly I) need to keep these copies in sync. We meet weekly, and each time we create a playlist in one copy of MediaMonkey that needs to be propagated to all other copies. MediaMonkey has an easy technique for importing a playlist: if MM is already running, you can select an M3U playlist with File Explorer and do a "Open With MediaMonKey". However, the MP3 file paths in the playlist must match the paths in the local library and MM database. Our library directory structure is the same in each copy of our library, but the drive letter and high level directories differ among our multiple copies so a playlist exported from one copy cannot be directly imported into another. paths in the playlists can easily be edited, but some of the people trying to import the playlists are not technical and have no idea what a path is. Therefore, I want to automate the process.

    OK. That's a lot of verbiage. Sorry.

    I want to write a script to be invoked by somebody wanting to import a playlist. The script will
    1. Prompt the user for the location of the of the playlist.
    2. Determine the path to the local library.
    3. Read the playlist and modify the path statements to use the local library's drive letter and high level directories.
    4. Write the modified playlist.
    5. Do the equivalent of "Open With MediaMonkey" for that newly written file.


    I'm not sure that step 5 can actually be done. I may have to find an alternative to that.

    Step 2 could be tricky, too, because there could be multiple local copies of MediaMonkey on the computer - one on an internal drive and another one a USB flash drive. Only one would be running, but determining which is running could be tricky.
      My Computer


  4. Posts : 1,223
    W10-Pro 22H2
       #4

    I don't know if it would work, but I would try to solve that problem by creating a junction to the top level of the common folder structure - the level would be different on each machine, but the junction would have the same name.

    A 'script' that can open, edit and save a playlist would be non-trivial.
      My Computer


  5. Posts : 720
    Win10 x64 Pro - 2 desktops, 2 laptops
    Thread Starter
       #5

    mngerhold said:
    I don't know if it would work, but I would try to solve that problem by creating a junction to the top level of the common folder structure - the level would be different on each machine, but the junction would have the same name.
    That occurred in the middle of the night. I already have a set of scripts - .bat files - that operate on the "local" library and program's data files. There is not problem at all if the script executing from a directory at the same "level" as the library.

    The only trick will be translating
    Code:
    FOR %%A IN ("%~dp0.") DO Set pathname=%%~dpA
    into another language (such as vbs).

    mngerhold said:
    A 'script' that can open, edit and save a playlist would be non-trivial.
    Hmm. Maybe I'm over-simplifying this in my mind. I've seen some vbs scripts that do something similar, I think.
      My Computer


  6. Posts : 744
    Windows 10/11
       #6

    If I understand correctly, the root of the issue is that the playlist files contain file paths that differ from machine to machine. Playlists should NOT contain file paths. That's what I would try to fix, if possible. But if that's not practical to do, I would want to coordinate with the users and have them all set up the software the same way using the same directory structure. As @mngerhold suggested, you may be able to essentially get everyone on the same page with folder structure by using junctions, but I fear this may be too complex for non-technical users to set up and, even if you script the junction set up, it may lead to future confusion. I would have to be one of the users with the same software and files installed on my computer to really know for sure what would work best.

    If you still want to pursue a script that edits the playlist files, please post a sample playlist (just a few lines are all that's needed), so I can see the format, and I'll post a sample script for you.
      My Computer


  7. Posts : 720
    Win10 x64 Pro - 2 desktops, 2 laptops
    Thread Starter
       #7

    LesFerch said:
    If I understand correctly, the root of the issue is that the playlist files contain file paths that differ from machine to machine. Playlists should NOT contain file paths.
    Huh? That's all an M3U playlist contains (other than comments). According to Wikipedia:
    There is no formal specification for the M3U format; it is a de facto standard.

    ...

    Each entry carries one specification. The specification can be any one of the following:

    • an absolute local pathname; e.g., C:\My Music\Heavysets.mp3
    • a local pathname relative to the M3U file location; e.g. Heavysets.mp3
    • a URL


    LesFerch said:
    That's what I would try to fix, if possible. But if that's not practical to do, I would want to coordinate with the users and have them all set up the software the same way using the same directory structure.
    That can't be done. For the copy of the software, library, and database on USB flash drives, there's know way to know what drive letter will be assigned. If nothing else, it depends on whether the the flash drive with the library and program is inserted first or a flash drive with a playlist. Also, for the 3 commonly used laptops we have, there is also a backup copy of the software, library, and database on an internal drive. The backup library and database are months out of date but still usable if the flash drive is lost or damaged. At the very least I would want my script to be able to handle both the resident backup copy and the flash drive copy.

    LesFerch said:
    ... If you still want to pursue a script that edits the playlist files, please post a sample playlist (just a few lines are all that's needed), so I can see the format, and I'll post a sample script for you.
    I think you misunderstand my request. I have plenty of samples of vbs code for reading and writing files, and I suspect I can cobble together code that does the pattern matching and string replacing needed for the editing. I can probably also manage the program invocation that will be the last step of the process. I just have no idea how to do display something similar to File Explorer that will allow the user to specify the playlist file.

    But if you are really interested, here are a few lines from one of the exported playlists:
    Code:
    H:\FDMusic\Steve\Misc07\Setnja.mp3
    H:\FDMusic\Veselo2018-VanGeel\Syrtós kitrínou.mp3
    H:\FDMusic\Steve\Misc14-NoMD\Sano Duso.mp3
    H:\FDMusic\Denis\03\Legnala Dana.mp3
    H:\FDMusic\Steve\Misc03\Kalamantiano Nisava.mp3
    And here's another:
    Code:
    D:\MMV4\FDMusic\Svet\Pravoto Ai_da_idem_Qno_v_Gorniq_Poroi.mp3
    D:\MMV4\FDMusic\Balkanarama\10 Syrto Argitiko.mp3
    D:\MMV4\FDMusic\Denis\05\Pinosavka.mp3
    D:\MMV4\FDMusic\Steve\MiscBulgaria-NoMD\Pesen za Rayna Knyginya.mp3
    D:\MMV4\FDMusic\Steve\Misc07\Sumadinka.mp3
    D:\MMV4\FDMusic\AA-Temp\Unprocessed\TeacherMusic\2020-01-25 Kotansky Veselo - Taught\Romsko Phuro Pharo Oro, Macedonia.mp3
      My Computer


  8. Posts : 744
    Windows 10/11
       #8

    Sorry about the confusion on playlist paths. I must have been thinking about library or streaming playlists, not M3U files.

    Anyhow, the file input can be done in several ways:

    1) HTA (recommended)
    2) VBScript that uses MSHTA to access a file dialog
    3) VBScript that uses PowerShell to access a file dialog
    4) A command line file dialog exe
    5) Using the OpenFileDialog method from the VBSEdit Toolkit

    The HTA option will allow you to easily expand on the interface. Just put your VBScript code in the "ProccessFile" sub.

    I wrote the above command line file dialog exe for use with my HTA because I wanted a File Explorer dialog for both open and save, but it's unnecessary if you just need the file dialog for open only.

    Note: I tried to paste the HTA code here directly within "[Code]" tags, but the Cloudfare security software interpreted it as an attack.

    Question: Do you want to prompt the user to choose a single file, multiple files, or a folder of files?
    Last edited by LesFerch; 06 Dec 2021 at 09:19.
      My Computer


  9. Posts : 1,223
    W10-Pro 22H2
       #9

    A quick look at one of my (Media Player) .m3u files shows it is using relative paths:
    ..\misc\Nene - 99 Red Balloons.mp3
    As such, I imagine it would work fine if it sat in the same relative (to the music files themselves) position on any drive/folder. I don't know if MediaMonkey forces absolute paths, or can be made to work with relative ones. As I now see that the m3u files are plaintext, then editing won't be that tricky - but still a lot of work every time an update is required. I shall bow out to Les.
      My Computer


  10. Posts : 744
    Windows 10/11
       #10

    mngerhold said:
    A quick look at one of my (Media Player) .m3u files shows it is using relative paths:
    ..\misc\Nene - 99 Red Balloons.mp3
    As such, I imagine it would work fine if it sat in the same relative (to the music files themselves) position on any drive/folder. I don't know if MediaMonkey forces absolute paths, or can be made to work with relative ones.
    Good point. It would be so much easier to maintain if relative paths were used.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:08.
Find Us




Windows 10 Forums