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

Does not work for me #1

Open
mahush opened this issue Sep 9, 2022 · 1 comment
Open

Does not work for me #1

mahush opened this issue Sep 9, 2022 · 1 comment

Comments

@mahush
Copy link

mahush commented Sep 9, 2022

Hey @jordanbaird, your package is exactly what I was looking for. Thanks a lot. But unfortunately it doesn't work for me. I created a minimal console application to give it a try. I expect this line to open TextEdit and put the string "Hello".

try KeySender(for: "Hello World").openApplicationAndSend("TextEdit")

But unfortunately only TextEdit opens but not text appears. I already grant accessibility permissions for my console application. Do you have any idea what else could be missing?

EDIT 1: I found out that the behaviour described is related to that: https://stackoverflow.com/q/63094246. The conclusion is that adding a sleep after the line above helps. Does anyone knows a better solution?

Cheers
mahush

@jordanbaird
Copy link
Owner

jordanbaird commented Sep 30, 2022

Looks like this is a lot more finicky than I'd originally thought. I've been experimenting with using DispatchQueue instead of sleep, as running it async seems like the better option, rather than holding up the entire process. It works, as long as the target app (in this case, TextEdit) is completely closed beforehand. If it's already running I'm having trouble getting it to work consistently.

EDIT: After more experimentation, it looks like the process that's doing the sending is finishing before it has the chance to actually send anything, so I think DispatchQueue is a no go. When KeySender opens an app, it just runs the open command, waits for it to finish, then tries to send the event. I'm guessing it works in that case because of the delay in waiting for the command to finish, which is keeping the process alive longer. I'll keep trying things, but I feel like it's ultimately going to come down to some sort of sleep function, which isn't ideal. I guess there's the option of using some sort of background helper process, if we want to go down that route.

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

No branches or pull requests

2 participants