The Unofficial Macro Scheduler Puzzler of the Week 6

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

The Unofficial Macro Scheduler Puzzler of the Week 6

Post by JRL » Sun Oct 20, 2013 1:06 am

I thought I'd write a little script that wrote to itself.

Open the Macro Scheduler main menu and start a new macro. Paste in the following line. Save the script as "Write to me" and exit the editor.

Code: Select all

WriteLn>%script_dir%Write to me.scp,wres,MessageModal>I wrote to me
Running the script once should add a MessageModal> line. Running the script a second time should display the message we wrote the first time we ran the script. For some puzzling reason it doesn't work. Hmmm, very puzzling.

How would you go about writing a script that can modify itself? 20 points and bragging rights to the "best" solution as determined by our panel of judge.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Tue Oct 22, 2013 5:22 am

Hi JRL,

This one was so easy, it makes me wonder if its a trick question.

It doesn't work because you omitted the slash \ after %script_dir%

Just add the slash \ as shown below and it works fine...

Code: Select all

WriteLn>%script_dir%\Write to me.scp,wres,MessageModal>I wrote to me
Or was there something else you were looking for? :)
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Oct 22, 2013 5:35 am

It also won't work when run from within the editor because the script is locked for editing and can't be written to.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Oct 22, 2013 6:21 am

Good job jpuziano!
...trick question
Or puzzler... One and the same.
This one was so easy...
Then why did it take two days for a response?

There are several system variables that are directory names:
  • WIN_DIR
    Windows Directory Path

    SYS_DIR
    Windows System Directory Path

    SYS_NATIVE
    Native System Directory Path Bypassing 64 Bit Redirection

    TEMP_DIR
    Windows Temp Directory Path

    DESKTOP_DIR
    User's Desktop Path

    USERDOCUMENTS_DIR
    User's Documents Path

    PROGRAM_FILES
    Program Files Folder (Will be x86 folder if running on x64)

    PROGRAM_FILES_NATIVE
    Native Program Files Folder (e.g. "Program Files" not (x86) on x64)
If you want to use any of these as part of a file name, they all need to be surrounded by percents, and all but TEMP_DIR need to be followed by a backslash.

@Marcus,

That's true. Hadn't thought about that but it could have thrown off a potential correct answer if they only tried it in the editor.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Tue Oct 22, 2013 5:00 pm

JRL wrote:
jpuziano wrote:This one was so easy...
Then why did it take two days for a response?
I responded when I saw it... I'll have to get back to reading the forums daily.
JRL wrote: There are several system variables that are directory names:
  • WIN_DIR
    Windows Directory Path

    SYS_DIR
    Windows System Directory Path

    SYS_NATIVE
    Native System Directory Path Bypassing 64 Bit Redirection

    TEMP_DIR
    Windows Temp Directory Path

    DESKTOP_DIR
    User's Desktop Path

    USERDOCUMENTS_DIR
    User's Documents Path

    PROGRAM_FILES
    Program Files Folder (Will be x86 folder if running on x64)

    PROGRAM_FILES_NATIVE
    Native Program Files Folder (e.g. "Program Files" not (x86) on x64)
If you want to use any of these as part of a file name, they all need to be surrounded by percents, and all but TEMP_DIR need to be followed by a backslash.
Yes, this last bit about TEMP_DIR being different has thrown me a few times... so when I use one of the above system variables, I usually write a quick one-liner and run it in the editor to see what the value is... and to see if it includes the trailing backslash or not...

MDL>%TEMP_DIR%

...then code accordingly. Yes I know I could use the Debugger and Watch List but the above is faster/easier.

Of course it would be nice if ALL the above System Variables that are Directory Names included the trailing slash... however since changing that now would break a lot of old code, leaving it alone seems better... I guess it just evolved this way.

I often visit the following Help Topic though...
Current Help File 'System Variables' Topic wrote:System Variables

Environment Specific Values:

OS_VER
Operating System

WIN_DIR
Windows Directory Path

SYS_DIR
Windows System Directory Path

SYS_NATIVE
Native System Directory Path Bypassing 64 Bit Redirection

TEMP_DIR
Windows Temp Directory Path
Since TEMP_DIR is the only one that is different, could we get this help topic updated... perhaps like the following?
Possible Updated Help File 'System Variables' Topic wrote:System Variables

Environment Specific Values:

OS_VER
Operating System

WIN_DIR
Windows Directory Path

SYS_DIR
Windows System Directory Path

SYS_NATIVE
Native System Directory Path Bypassing 64 Bit Redirection

TEMP_DIR
Windows Temp Directory Path *includes a trailing backslash \
That would be all I'd need to remind me that TEMP_DIR is the special one.

Thanks and take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Tue Oct 22, 2013 11:25 pm

I'd never noticed that. After all these years!

I'll mention the help file to Marcus and ask if he wants me to edit it.

JP, I just noticed your 9th anniversary of joining the forum is coming up. Happy anniversary. :D
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts