Start with DOpus scripting

Hello!

So, after having this discussion: Save positions of closed windows?

I was advised to should look for my solution in scripting. Two questions:

  1. Is there something like a beginner's guide that covers the basics?
  2. In my case, I'd like opus every time it has to open a window for a folder, to look into said folder, read a saved layout, and open it as described in that file automatically. Would it be possible to do exactly that? Or will there have to be any compromises?

Many many thx!

I think your best bet is to start in the help manual under the Scripting and Scripting Reference sections. There are several examples in the manual as well as a library of scripts released by both GPSoft and other forum users in Script Buttons & Add-Ins forum which you can download and learn from.

As an example of how to get started quickly (you'll be better off if you've had prior scripting experience), I think what I did in my LinkedTab_AutoOpen_Handler script add-in could be easily adapted to do what you described in that other thread you linked to...

In that script, I associate two different folder paths, and implemented the script as an 'event handler' that gets called when Opus fires the OnAfterFolderChange. What this means is that when you enter a folder (dbl-clicking on a folder in the lister, using a button or hotkey that runs a 'Go' command to open a folder, typing it in the address bar, etc), Opus calls the script and passes it a bunch of info, including the path of the folder you just opened. With that information, my script compares the folder path opened to see if it is included in the list of folders that can be paired with one another by the user in the script options.

Rather than use a file in each folder, you can adapt a similar technique such that you can pair up a folder path with the layout you want the script to load when you open the folder path... You don't "have to" of course, but it prevents you from needing to leave extra files around all over the place just to trigger the script. I can post an example modification to my own script here for you to check out, use, learn from or ignore as you see fit...

Well, everything I said still stands... but there's a problem is you do in fact want to use saved Layouts.

When a Layout opens a folder path you will enter an infinite loop... your folder gets opened, the script will load the layout, which reloads the folder and causes the script to fire again and open the layout again, and on and on. At least - if you use the 'Prefs' command to load the layout.

@Jon/Leo: for this sort of thing, looks like the Prefs command could use the NOSCRIPT option now. Also - while testing an alternative using the 'Go LAYOUT=<layout_name>' command, this command seems broken in 12.2.6 (not sure about older versions). Running this command from a standard toolbar button - nothing at all happens.

I'd make the script record window sizes (you could store them in a path->size map, and save it in a variable with persist=true), then have the script resize the window, rather than use layouts for this.

I suspect you're confusing Go LAYOUT=... and Prefs LAYOUT=... too.

thx for the replies! I'll check them out.

@steje
yes plz, I would like to have that script as a starting point

BTW is there an edit button for the posts here that I'm missing, or is this by design?

If you link your account you can edit your posts in this part of the forum.

Editing will still be disabled in the Help & Support area.

See Why can't I edit my posts? in the FAQs for more detail.

@Leo: Prefs LAYOUT= is what I tried first... and the command itself works fine. The problem is that opening a layout using the Prefs command for a folder based in an OnXFolderChange event handling script causes an infinite loop since the Prefs command has no NOSCRIPT option.

But yeah - I forgot that Go needs a folder, so a Go CURRENT LAYOUT= command works fine.

@vulture: editing posts is generally disabled for most users: Why can't I edit my posts?

Here's a quick modification to my other script that should be ONE way of getting things started for you. There are easier ways - I have lots of additional ~stuff in my script to handle various controlling options and log messaging functions and what-not. And you can certainly keep files on disk with whatever info you want in order to control which folder and layouts get processed. But here's an "example" of how it can be done:

Layout_AutoOpen_Handler.osp (3.25 KB)

Layout_AutoOpen_Handler v1.0.0:

In the Preferences / Toolbars / Scripts page listing for this script, click on the script link and configure the FolderLayoutList option to list a folder path and layout name combination like the following:

lib://My/projects/opus/scripting && my_Scripting

The folder path is the path to the folder which you want to trigger the script. Followed by a double ampersand as a delimiter. Followed by the name of whatever saved lister Layout you want the script to call when you open the folder...

I'll explain other options another time.

We'll add the NOSCRIPT argument to the Prefs command in the next update.

Sweet! I just stuck with Layouts for my example of what this user asked for because they store so much more than just the size and position, and if they wanted any of those other lister attributes preserved it didn't make sense to store all of that stuff in something ~other than a layout. But, I digress... Thanks.

@vulture: let me know if you'd like an explanation of how this example script works. Right now, it loads the sepcified layout in a new window - but you could add other options for some more control over what happens to the original lister window you entered the folder from. But beyond this, other users have posted many other scripts to the forum, so lots of opportunity to learn via hacking :slight_smile:.

Thx for everything guys! I'll be back with more questions after I take a look at everything you've proposed! :slight_smile:

Sure thing!

BTW - I've posted a cleaned up version of this script to the Script Buttons & Add-Ins forum...