Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS Global Hotkey Docs #1593

Closed
karlhorky opened this issue Apr 28, 2021 · 9 comments · Fixed by #1845
Closed

macOS Global Hotkey Docs #1593

karlhorky opened this issue Apr 28, 2021 · 9 comments · Fixed by #1845
Assignees
Labels
MacOS MacOS related

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Apr 28, 2021

Is your feature request related to a problem?

It would be nice to be able to use a global hotkey with macOS, just like the Linux instructions for Ubuntu / Gnome / KDE.

I would take over writing a short section on this in the docs, but cannot figure out a nice (fast) way to achieve this :( If the Flameshot screenshot doesn't launch fast, then it's not as much value as it could be.

I have tried the following:

  1. Running /Applications/flameshot.app/Contents/MacOS/flameshot gui - this appears to do nothing
  2. Trying an Automator Apple Script as follows - the script below worked, but it launched super slow - took like 5 seconds to launch
tell application "System Events" to tell process "Flameshot"
    tell menu bar item 1 of menu bar 2
        click
        click menu item "Take Screenshot" of menu 1
    end tell
end tell

Credit for the Apple Script: https://stackoverflow.com/a/16497564/1268612

Anyone have any ideas how to do this?

@holazt holazt added the MacOS MacOS related label Apr 28, 2021
@MatanRubin
Copy link

Regarding 1, seems like it's because of #1292.

My fingers aren't flexible enough to use the default Cmd-Alt-Shift-4 global hotkey for flameshot, so I used a separate tool (BetterTouchTool, not free) to map Cmd-4 to Cmd-Alt-Shift-4, it works really well.
You can get similar results with any other free keyboard mapper.

@karlhorky
Copy link
Contributor Author

You can get similar results with any other free keyboard mapper

Nice! Can you elaborate on the settings that you used for this? Is it just mapping cmd-4 to cmd-alt-shift-4?

@karlhorky
Copy link
Contributor Author

the default Cmd-Alt-Shift-4 global hotkey for flameshot

Oh, there's a global hotkey already?? 🤯 Where did you find this?

This is already almost good enough!

I would add a quick note to the docs to make this more prominent, if you can point me to the source of this information.

@MatanRubin
Copy link

😄
I got it from the configuration menu:
image

I see that README.md has the keyboard shortcuts for Linux but not macOS, you can probably contribute there

@borgmanJeremy
Copy link
Contributor

I see that README.md has the keyboard shortcuts for Linux but not macOS, you can probably contribute there

Yes please submit a PR to clarify this and I'll get it merged.

@Faetu
Copy link

Faetu commented May 10, 2021

 Hi @karlhorky
 
 The global shortcut, Is a mess.
 Because of this, I try to solve this the same way like you do, over automator.
 And yes, it takes ~5 sec to start the action. I play a little bit with the delay function and this Is my Solution:

ignoring application responses
	tell application "System Events" to tell process "Flameshot"
		tell menu bar item 1 of menu bar 2
			click
		end tell
	end tell
end ignoring
delay 0.1
do shell script "killall System\\ Events"

tell application "System Events" to tell process "Flameshot"
	tell menu bar item 1 of menu bar 2
		click menu item "Take Screenshot" of menu 1
	end tell
end tell

It is way faster, but sometimes I need to hit the button twice or more then just twice. I don't know why, but it is the best solution at the moment.

best regards

@Faetu
Copy link

Faetu commented May 10, 2021

Hi @karlhorky

I have now a solution for the problem, that the script doesn't work always.
The problem is the focus, if you focus an application that doesn't have the permission to execute applescripts, then the system will block the script and ask for permissions.
I add a second part of script in the automator, that part sets the focus to flameshot and runs the "take screenshot" script:

image

:) I hope this works!

Focus-part:

tell application "System Events"
	tell application "flameshot" to activate
	repeat while (value of attribute "AXfocused" of group 1 of scroll area of ¬
		process "Flameshot" is {false})
		keystroke "<" using command down
	end repeat
end tell

Take screenshot part:

ignoring application responses
	tell application "System Events" to tell process "Flameshot"
		tell menu bar item 1 of menu bar 2
			click
		end tell
	end tell
end ignoring
delay 0.1
do shell script "killall System\\ Events"

tell application "System Events" to tell process "Flameshot"
	tell menu bar item 1 of menu bar 2
		click menu item "Take Screenshot" of menu 1
	end tell
end tell

capric98 added a commit to capric98/macOS-miscellaneous that referenced this issue Jun 14, 2021
@mmahmoudian mmahmoudian self-assigned this Jul 16, 2021
@nippyin
Copy link

nippyin commented Jul 16, 2021

Hi @karlhorky

I have now a solution for the problem, that the script doesn't work always.
The problem is the focus, if you focus an application that doesn't have the permission to execute applescripts, then the system will block the script and ask for permissions.
I add a second part of script in the automator, that part sets the focus to flameshot and runs the "take screenshot" script:

image

:) I hope this works!

Focus-part:

tell application "System Events"
	tell application "flameshot" to activate
	repeat while (value of attribute "AXfocused" of group 1 of scroll area of ¬
		process "Flameshot" is {false})
		keystroke "<" using command down
	end repeat
end tell

Take screenshot part:

ignoring application responses
	tell application "System Events" to tell process "Flameshot"
		tell menu bar item 1 of menu bar 2
			click
		end tell
	end tell
end ignoring
delay 0.1
do shell script "killall System\\ Events"

tell application "System Events" to tell process "Flameshot"
	tell menu bar item 1 of menu bar 2
		click menu item "Take Screenshot" of menu 1
	end tell
end tell

Need some help to set "Ctrl+`" as a shortcut to capture screen shot. I tried keystroke using "Ctrl+`" surely doing something wrong.

image

@karlhorky
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MacOS MacOS related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants