On Feb 19, 2020, at 2:00 PM,Jody Bevan wrote:
> I want to let the Administrator / Designer in a compiled database be able to
> launch the Runtime Explorer without having to remember the keyboard shortcut
> to do this.
>
> The way I was thinking of doing this was a button on screen they click on
> that would post the keyboard shortcuts for the runtime explorer. For example
> on the MacOS doing the following:
>
> If (Is macOS)
> POST KEY(-101;Shift key bit+Command key bit)
> End if
>
> or use
>
> POST KEY(-101;Shift key Mask+Command key mask)
>
> This does not seem to work. Where is my thinking wrong?
Hi Jody,
I wanted to do the same thing back in 2018 and ran into the same problem. You
would think the POST KEY code you wrote — and I wrote — would work, but it
doesn’t. Could be the need to use a function key is causing the issue. The
workaround I came up with is to have an AppleScript post the event.
I also work in 4D Server Team Development and each developer has his own 4D
User that they log in under. Only the “Designer” can make the Runtime Explorer
appear. So the code below also handles that.
Read the method comments for what you need to do to allow AppleScript to
control your computer.
I right-click this method and choose “Run Method” in the Explorer in Design,
wait a couple of seconds and the Runtime Explorer appears. Work in v16 and v17.
// ===========================================
// PROJECT METHOD: 1 Show Runtime Explorer
// PARAMETERS: none
// DESCRIPTION: This is a developer tool that will display the
// Runtime Explorer in the development environment.
// Runtime Explorer can only be displayed if the "Current user"
// is "Designer". All developers use 4D Team Developer
// and log in to their own user account. So no one is ever logged in
// as "Designer" by default.
// The method uses tricks and ideas from the iNUG discussion
// started by Jody Bevin. John DeSoi developed this method of
// allowing the Runtime Explorer to be display by any user.
// The trick it to temporarily sign in as Designer, get the Runtime
// Explorer window open and then switch back to the original
// 4D user account. I had to adapt it to make it work with macOS 10.13.
// This will only work on macOS because it uses AppleScript
// to post system events.
// In order for this to work, you need to add "System Events" application
// to System Preferences -> Security & Privacy -> Privacy
// This will allow AppleScript to control programs on your computer.
// "System Events" is located in /System/Library/CoreServices/
// CREATED BY: Tim Nevels, Innovative Solutions ©2018
// DATE: 5/5/18
// LAST MODIFIED:
// ============================================
// declare local variables
C_TEXT($currentUser_t;$applicationName_t;$command_t;$inputStream_t;$outputStream_t;$errorStream_t)
// check if running on macOS
If (Is macOS)
// get current user
$currentUser_t:=Current user
// Switch to Designer user
CHANGE CURRENT USER("Designer”;"xxxxx")
// let 4D breath a little
DELAY PROCESS(Current process;10)
// get current 4D application name
$applicationName_t:=utl_Path_GetFileName (Application file)
$applicationName_t:=Replace string($applicationName_t;".app";"")
// build AppleScript to post system event Command-Shift-F9 to 4D
$command_t:="osascript"+\
" -e 'tell application \"System Events\"'"+\
" -e 'tell application \""+$applicationName_t+"\" to activate'"+\
" -e 'key code 101 using {shift down, command down}'"+\
" -e 'end tell'"
// run AppleScript
LAUNCH EXTERNAL
PROCESS($command_t;$inputStream_t;$outputStream_t;$errorStream_t)
If ($errorStream_t#"") // problems
TRACE
End if
// let 4D breath a little
DELAY PROCESS(Current process;10)
// set current user back to original value
CHANGE CURRENT USER($currentUser_t;”xxxxxx")
Else
ALERT("Sorry, this developer tool currently only works on macOS.")
End if
Tim
Tim Nevels
[email protected] <mailto:[email protected]>
Innovative Solutions
785-749-3444
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive: http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************