When I run the following code from terminal the pop-up box will become frontmost but with KM it will not. I get no error message, it's just that the window will not become frontmost.
Don't worry about this code:
timerbox('hey','countdown', time=1)
This is the code that is not working but there is no error message:
os.system(f'''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')
Yes, it's part of a larger script. I can't run apple script first, then run python inside of apple script because I am 100 times more familiar with Python and because I hate Applescript. I tried learning Applescript but then I figured out that I could do almost everything I wanted with Python that I could with Applescript except for a very short number of things.
Okay. When posting such things please post the minimum possible working code. This will make it more likely that someone will help you.
I know in this case the AppleScript part isn't working for you, but the rest of the script really should be turnkey.
This works (change the app-name as needed):
#!/usr/bin/env python
import os
cmd = """osascript -e '
tell application "System Events"
tell application process \"Finder\"
set frontmost to true
end tell
end tell
'"""
def stupidtrick():
os.system(cmd)
stupidtrick()
In general I recommend that people NOT try to compress scripts down to one-liners, as it makes them more difficult to read and to debug.
I have known an app called Deskovery, which could listen global shortcut and then make current window toggle always-on-the-top or toggle semitransparent.
So maybe every window of MacOS can receive corresponding events, so that they could achieve those.
Something like Swift or Objective-C, which Deskovery may developed in, might have more abilities than Applescript.
This is very low-level and requires "hacking" the macOS, as there is no official API from Apple that allows a utility to access other applications' windows in this way.