This is a Dynamic Library solution to renaming subtools and layers on Mac OS X, while also allowing the zscript to continue without user interaction.
Problem: In a ZScript where Tool > Subtool > Rename or Tool > Layer > Rename is pressed, the ZScript loses focus and the user is expected to complete the task. The ZScript cannot continue until the user enters a new name and presses enter or cancels the rename dialog window.
Solution: Our ZScript makes a call to a Dynamic Library where we use a NSTimer object to delay our call to functions that will simulate keypresses after our Dynamic Library has returned control to ZBrush. Back in ZScript we immediately press Tool > Layer > Rename and wait for the NSTimer to do it’s thing.
Issues: During select circumstances ZBrush might take longer to actually press and display the rename layer dialog, thus passing the point where NSTimer calls the keypress function. I had it happen once during low memory and high cpu usage on my meagre 2012 MacBook Air. During normal usage and on newer cpus it should be fine.
How to use: Unzip the Xcode project and open it. Go into the advanced section of File > Project Settings and change the build location to fit your ZScripts location. From your ZScript you would call the Dynamic Library and then press the rename button:
[FileExecute, “zDLL.lib”, “KeyPress”, “MyNewName For SubTool”]
[IPress, “Tool:Subtool:Rename”]
By default the KeyPress function calls [MOKeyPresser simulateKeypressesOf: (char*)inputString withDelay: (NSTimeInterval)0.1]; which simulates the keypress of each character in inputString after the delay. You can also use [MOKeyPresser simulatePasteOperationOf: (char*)inputString withDelay: (NSTimeInterval)0.1]; which copies inputString into the clipboard and simulates a Command + V key press after the delay. The first method is probably preferable as the paste command shortcut may vary depending on the OS localization.
You should also be aware that simulateKeypressesOf: withDelay: converts all characters to lower case and only supports the english alphabet and some special characters.
I hope somebody finds this useful and maybe extends it a bit.
Note: It is currently only a 32 bit library, ZBrush 4R5 on Mac fails to load the library when I compile it as a 32 and 64 bit library.