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

Handling multiple Xcode installs #8

Closed
wants to merge 6 commits into from

Conversation

idpaterson
Copy link

The path of the frontmost application is now used to distinguish multiple Xcode installs, which should fix #6.

Additionally, I developed a robust technique to find the current active document in Xcode 4 since the approach in the first commit was not working in assistant editors. While this was trivial in Xcode 3, there were no good solutions out there for Xcode 4 that did not break down when pitted against multiple windows, tabs, or assistant editors.

There are a few ways that we can interact with the active document in AppleScript without actually having a reference to it, for example emitting keystrokes or changing the text selection. The approach used in this pull request is to:

  1. Use the Xcode menu to select all text in the active document
  2. Iterate all open text document instances and record their current selection value
  3. Emit an up arrow keystroke to deselect the active document
  4. Iterate all open text document instances and find the one with a different selection value
  5. Return this as the active text document and operate on it

This approach should work well until Xcode's AppleScript bindings are improved. Since the menu_click routine could be subject to system localization issues, I made a small "config" section at the top for convenience.

…nstalls. Active document is detected based on the window title since the previous approach was occasionally grabbing a document in a different window within the same process. Should resolve tonyarnold#6.
… 4, regardless of how many windows, tabs, or assistant editors are in use. The Re-Indent workflow no longer saves the document after processing since the other workflows did not share that behavior.
…sponding characters. Fixed by using herestring input rather than piping the string to uncrustify via echo.
@tonyarnold
Copy link
Owner

Doing a fresh checkout of your workflows, I can't open them locally. Automator thinks that they are corrupt — can you just check that everything is OK on your end?

@idpaterson
Copy link
Author

Sorry about that, it should be fixed now. That's what I get for editing outside of Automator.

@tonyarnold
Copy link
Owner

Thanks, @idpaterson — I'm going to need to spend some time with your changes, as your revised scripts don't work on my setup.

…ith detecting the active document. This should allow enough time for the user to release any modifier keys that would affect the keystroke emitted by the script.
@idpaterson
Copy link
Author

Shot in the dark... are you running the service with a keyboard shortcut that uses the Option or Control keys? There is apparently no way to send a keystroke unadulterated by the current keyboard state, so the active document detection portion of my changes was sending the Up Arrow key with either the Shift or Control modifiers if the service keyboard shortcut included those modifiers. In that situation, the Up Arrow does not change the selection in the active document and no active doc is found. Other people experiencing that problem in AppleScript used a 200ms delay to allow time for the keyboard shortcut to be released.

@tonyarnold
Copy link
Owner

I am, yes — I'll give your updated code another shot, but this is becoming very fragile. I think I need to look at making this a proper Xcode plugin now there are examples available.

@tonyarnold
Copy link
Owner

OK, shoot me a private message: It's not perfect, but I have a proof-of-concept of a native Xcode plugin that does the same thing as this automator workflow. It's already more reliable, and faster.

I'm planning on making a commercial product out of it, so I'd like to keep the binary private for now, but I'd love to get your feedback!

@idpaterson
Copy link
Author

That sounds like a better direction, glad to hear it!

@tonyarnold tonyarnold closed this Jan 26, 2017
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

Successfully merging this pull request may close these issues.

Services do not work with multiple Xcode installs
2 participants