Ben Lunder Posted April 26, 2023 Report Share Posted April 26, 2023 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 Quote Link to comment Share on other sites More sharing options...
acantor Posted April 26, 2023 Report Share Posted April 26, 2023 (edited) 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 April 26, 2023 by acantor I noticed a subtle bug in the script. Fixed it. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 26, 2023 Report Share Posted April 26, 2023 What I did was to use a random number generator to generate a number in the ASCII range A-Z and then convert that integer to the letter. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 26, 2023 Report Share Posted April 26, 2023 acantor beat me to it. Ignore my post. It was a waste. Quote Link to comment Share on other sites More sharing options...
acantor Posted April 26, 2023 Report Share Posted April 26, 2023 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"/> Quote Link to comment Share on other sites More sharing options...
Ben Lunder Posted April 26, 2023 Author Report Share Posted April 26, 2023 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. Quote Link to comment Share on other sites More sharing options...
Ben Lunder Posted April 26, 2023 Author Report Share Posted April 26, 2023 ok, I got a random name in the text box but couldn't figure out the rest so can't see how to copy %filename% to the clipboard and paste it. I tried looking at the clipboard command and the help on it but no luck. Quote Link to comment Share on other sites More sharing options...
acantor Posted April 26, 2023 Report Share Posted April 26, 2023 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 Quote Link to comment Share on other sites More sharing options...
Ben Lunder Posted April 26, 2023 Author Report Share Posted April 26, 2023 Ah, that works perfectly, and so simple! Thanks a lot. 😀 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.