Jump to content
Macro Express Forums

Need random filename paster


Recommended Posts

Trying to create a macro that would create a random filename and paste it into a text doc or save prompt by using a hotkey. I can see nothing like that under keyboard. I made a macro using encrypted text but it simply pastes the same seed string I put in the command. I was hoping it would encrypt it into printable characters. When I look at the help I can't quite follow its purpose as it only seems to hide what you are typing when creating the macro yet always prints out the unencrypted text. So why is that any different from putting that into keyboard text? But that's a side issue. Can anyone think of any other way to paste a random file name into a save prompt? It doesn't matter if the name already exists because one could always hit the hot key again, and anyway, a random 8 or 10 character name won't repeat that often

Link to comment
Share on other sites

Here's a way to generate a random ten-character string. The macro randomly picks characters from a list of 65: [A-Z] [a-z] [0-9] and the hyphen [-] and underscore [_].

 

Variable Set String %FileName% to "" // File name to build
Variable Set Integer %NumberOfCharacters% to 10 // Number of characters for the file name
// A list of every legal character for the file name. I've chosen 65 characters
Variable Set String %LegalCharacters% to "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890-_"
 
Repeat Start (Repeat %NumberOfCharacters% times)
  Variable Set Integer %RandomValue% to a random value between 1 and 65
  Variable Modify String: Copy part of text in %LegalCharacters% starting at %RandomValue% and 1 characters long to %Character%
  Variable Modify String %FileName%: Append Text (%Character%) // Build file name
End Repeat
 
Text Box Display: Ten character file name


<VARIABLE SET STRING Option="\x00" Destination="%FileName%" NoEmbeddedVars="FALSE" _COMMENT="File name to build"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%NumberOfCharacters%" Value="10" _COMMENT="Number of characters for the file name"/>
<COMMENT Value="A list of every legal character for the file name. I've chosen 65 characters"/>
<VARIABLE SET STRING Option="\x00" Destination="%LegalCharacters%" Value="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890-_" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<REPEAT START Start="1" Step="1" Count="%NumberOfCharacters%" Save="FALSE"/>
<VARIABLE SET INTEGER Option="\x05" Destination="%RandomValue%" Minimum="1" Maximum="65"/>
<VARIABLE MODIFY STRING Option="\x09" Destination="%Character%" Variable="%LegalCharacters%" Start="%RandomValue%" Count="1" NoEmbeddedVars="FALSE"/>
<VARIABLE MODIFY STRING Option="\x06" Destination="%FileName%" Value="%Character%" NoEmbeddedVars="FALSE" _COMMENT="Build file name"/>
<END REPEAT/>
<COMMENT/>
<TEXT BOX DISPLAY Title="Ten character file name" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Courier;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs40 \r\n\\par %FileName%\\lang1033 \r\n\\par }\r\n" Left="821" Top="432" Width="341" Height="266" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

Edited by acantor
I noticed a subtle bug in the script. Fixed it.
Link to comment
Share on other sites

Actually, Cory, your method works nicely. This is slightly convoluted: the script "flips a coin" and 50% of the time, changes an uppercase letter to a lowercase letter. I didn't try to include numbers or symbols (like hyphen and underscore) into the file name. But if that's what's wanted, I'm sure it can be done. 

 

Variable Set String %FileName% to ""
 
Repeat Start (Repeat 10 times)
  Variable Set Integer %x% to a random value between 65 and 90 // Pick an ASCII number between A and Z (65 - 90)
  Variable Set Integer %CoinFlip% to a random value between 1 and 2 // Flip a coin. 50% of time, compute the lowercase value
  If Variable %CoinFlip% Equals "1"
    Variable Modify Integer: %x% = %x% + 32
  End If
  Variable Set to ASCII Char %x% to %Char%
  Variable Set String %FileName% to "%FileName%%Char%"
End Repeat
 
Text Box Display: File Name


<VARIABLE SET STRING Option="\x00" Destination="%FileName%" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<REPEAT START Start="1" Step="1" Count="10" Save="FALSE"/>
<VARIABLE SET INTEGER Option="\x05" Destination="%x%" Minimum="65" Maximum="90" _COMMENT="Pick an ASCII number between A and Z (65 - 90)"/>
<VARIABLE SET INTEGER Option="\x05" Destination="%CoinFlip%" Minimum="1" Maximum="2" _COMMENT="Flip a coin. 50% of time, compute the lowercase value"/>
<IF VARIABLE Variable="%CoinFlip%" Condition="\x00" Value="1" IgnoreCase="FALSE"/>
<VARIABLE MODIFY INTEGER Option="\x00" Destination="%x%" Value1="%x%" Value2="32"/>
<END IF/>
<VARIABLE SET TO ASCII CHAR Value="%x%" Destination="%Char%"/>
<VARIABLE SET STRING Option="\x00" Destination="%FileName%" Value="%FileName%%Char%" NoEmbeddedVars="FALSE"/>
<END REPEAT/>
<COMMENT/>
<TEXT BOX DISPLAY Title="File Name" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Courier;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs40 %FileName%\\lang1033\\f1\\fs14 \r\n\\par }\r\n" Left="821" Top="432" Width="530" Height="249" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

Link to comment
Share on other sites

quick thanks to you both. I'll experiment with that.

 

Incidentally don't know if everyone knows, but I just found out that phind ai can create macros for Macro Express, and it should be more uptodate than gpt-4 because it can access the current web. In fact it's expert mode does use gpt-4

 

It did give me answer but I struggled to implement it so thought I'd check back here first.

Link to comment
Share on other sites

You probably don't need to use the clipboard to output the filename into the field. 

 

If the cursor is in already in the field, do this:

 

Text Type (Simulate Keystrokes): %FileName%

 

If the field doesn't have focus, you will have to start by giving it focus. For example, in the "Save As" dialog boxes in many applications, Alt+N is the hotkey to navigate to the "File name" field:

 

Text Type (Simulate Keystrokes): <ALT>n
Text Type (Simulate Keystrokes): %FileName%

 

But you must transfer the value of %FileName% to the clipboard, do this:

 

Clipboard Start Copy
  Text Type (Simulate Keystrokes): %FileName%
Clipboard End Copy

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...