johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.55k stars 565 forks source link

Keyboard shortcut not working #195

Closed vbklv closed 7 years ago

vbklv commented 7 years ago

The keyboard shortcut to Inject Code is not working within Xcode 8.2.1.

I have set it to Cmd+Shift+\ in System Preferences -> Keyboard -> Shortcuts -> Services against Inject Code but Xcode doesn't react when I am using the shortcut.

I tried restarting Xcode to no avail. In Xcode -> Services menu it says No Services Apply.

I am using the standalone Injection app on MacOS 10.12.2

What is the magic to make it work?

zenangst commented 7 years ago

@vbklv services is a bit weird, if you select some text in Xcode before going into Services, then it should show up.

vbklv commented 7 years ago

@zenangst Thanks, it worked and showed the services. But still, the shortcut that I've set to Inject Code is not working within Xcode.

johnno1962 commented 7 years ago

I’ve seen work inside Xcode but it has so many shortcuts itself you have to be careful not to have a clash.

vbklv commented 7 years ago

@johnno1962 actually Inject Source worked when some text was first selected. Now the problem is that it leaks and takes up all the memory. See screenshots:

screen shot 2017-01-17 at 10 35 42

screen shot 2017-01-17 at 10 35 33

If Inject Source is called within the Injection app, it works fine.

johnno1962 commented 7 years ago

I’ve not seen that!

vbklv commented 7 years ago

I tried restarting XCode and all, but to no avail. It still leaks.

johnno1962 commented 7 years ago

Seems to be in an infinte loop/recursion. Can you try running the app from the command line and see if it prints anything useful:

$ /Applications/Injection.app/Contents/MacOS/Injection

vbklv commented 7 years ago

This is the output:

Could not list directory file:///../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../
Could not list directory file:///../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../
Could not list directory file:///../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../

screen shot 2017-01-18 at 10 34 48

johnno1962 commented 7 years ago

Thanks very helpful thanks. Not sure what the problem is but I know where it is now.

johnno1962 commented 7 years ago

I’ve uploaded a new version which while it may not solve your problem will at least not loop like this. Can you give it a try?

vbklv commented 7 years ago

Confirmed, it doesn't solve the problem but at least it doesn't loop :)

screen shot 2017-01-18 at 11 37 02

johnno1962 commented 7 years ago

Would you like to TeamView so I can see whats going on? If so send details to injectionapp at johnholdsworth.com

johnno1962 commented 7 years ago

I’ve uploaded a version which logs the file it is trying to find the project for if you want to let me know the output.

dimohamdy commented 7 years ago

I face this problem but when you select code and press your shortcut that's work

ybeapps commented 7 years ago

I think I have the same problem.. Injection not working when executed with shortcut (first time try..)

It's also annoying to select text for the shortcut to do something... It took me a whole hour to find out by myself the text selection trick :(

It's hard to be new in something.... ;-)

ybeapps commented 7 years ago

Hi again... I don't understand about OS X services nothing, but:

https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/SysServices/Articles/properties.html

In the docs (about the plist file) there is the next statement: NSRequiredContext is a dictionary that can be used to limit when the service appears. Through judicious use of NSRequiredContext, you can ensure that your service appears only when it applies and does not clutter the Services menu when it is not applicable. Note: Always include this property, even when you do not require any filtering (in which case you specify an empty dictionary as the value). Otherwise the system registers your service, but does not automatically present it in the Services menu.

I don't see it in the injector app... (I couldn't add it too, maybe it's deprecated or something? I know nothing about all that stuff)

I hope it helps =]

johnno1962 commented 7 years ago

Thanks very much for this info. I missed this page. I can’t see a way the requirement that users select some text can be avoided though.

ybeapps commented 7 years ago

Just add empty array, it works!! And it's in the docs: Note: Always include this property, even when you do not require any filtering (in which case you specify an empty dictionary as the value). Otherwise the system registers your service, but does not automatically present it in the Services menu.

That's exactly what's happening now :)

‫ב-19 בינו׳ 2017, בשעה 11:13, ‏‏John Holdsworth ‏notifications@github.com כתב/ה:‬

Thanks very much for this info. I missed this page. I can’t see a way the requirement that users select some text can be avoided though.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

johnno1962 commented 7 years ago

Thanks, I’ve added this value to an updated app version. I think you still need to do two things to have the services menu entry come up: Enabled it in Sytem Preferences/Keyboard/Shotcuts and have some text selected.

ybeapps commented 7 years ago

ur right... Is there a way I can try to fix it myself instead of commenting annoying nonsense?

johnno1962 commented 7 years ago

how do you mean?

ybeapps commented 7 years ago

what should I clone to be able to build by myself? I can't find in the repository the plist file that defines the service so I can play with it and build it for testing...

johnno1962 commented 7 years ago

The source is not avilable at the moment though you should be able to edit the Info.plist in the distributed app if you want to try a few things. Services are a pretty arcane legacy feature of OSX though and I’m not sure you’ll be able to use a service that expects a string without a selection :(

zenangst commented 7 years ago

@johnno1962 maybe you could implement a global shortcut for injection that is configurable in a preference pane? It could also be scoped to when Xcode is the active application.

johnno1962 commented 7 years ago

Isn’t that what a service is? Is there something else I’m not aware of.. tell me more.

zenangst commented 7 years ago

I was thinking of something like this -> https://github.com/davedelong/DDHotKey

ybeapps commented 7 years ago

I tried before to change the plist in your app and reinstall... I got crash for checksum failed ;) your app is surely protected by Apple...

I think that service can be available anytime... but that's just what I think... I have a Mac for only one year... I'm not so familiar with all it has.. Services in OS X are new to me

‫ב-24 בינו׳ 2017, בשעה 23:17, ‏‏John Holdsworth ‏notifications@github.com כתב/ה:‬

The source is not avilable at the moment though you should be able to edit the Info.plist in the distributed app if you want to try a few things. Services are a pretty arcane legacy feature of OSX though and I’m not sure you’ll be able to use a service that expects a string without a selection :(

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

johnno1962 commented 7 years ago

looks very intersting. In truth, the “must select text” thing is sucking. I’ll take a look at DDHotKey thanks!

johnno1962 commented 7 years ago

I’ve uploaded a new version with a hard coded HotKey of control-= for injection which is indeed much better though you still need to remember to save the file. Not sure how to scope it to Xcode being active or even if that would be a good idea. Feedback welcome!

ybeapps commented 7 years ago

Thanks! I'll check this out

If you want to limit your service to Xcode only you can use (again) NSRequiredContext

Add a value in there as in the docs:

NSApplicationIdentifier is a bundle ID as a string or an array of such IDs. Your service will appear only if the bundle ID of the current application matches one of the given bundle IDs. For example, you could use this to limit a service to appear only in Xcode or in the Finder.

‫ב-25 בינו׳ 2017, בשעה 1:12, ‏‏John Holdsworth ‏notifications@github.com כתב/ה:‬

I’ve uploaded a new version that defines a HotKey of control-= for injection which is indeed much better though you still need to remember to save the file. Not sure how to scope it to Xcode being active or even if that would be a good idea. Feedback welcome!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

johnno1962 commented 7 years ago

Doesn’t that only work for services? The new code is using a Carbon HotKey (an even older API)

ybeapps commented 7 years ago

You're right, I thought you asked about services...

‫ב-25 בינו׳ 2017, בשעה 9:49, ‏‏John Holdsworth ‏notifications@github.com כתב/ה:‬

Doesn’t that only work for services? The new code is using a Carbin HotKey (an even older API)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

ybeapps commented 7 years ago

Works great Thanks!! You can mark the issue as resolved =]

ybeapps commented 7 years ago

I must add.. your plugin makes Stevia great!! =] now it's starting to be fun!!

johnno1962 commented 7 years ago

Happy to hear it.