source file links in xcode console output - xcode

A lot of dev environments have some basic parsing logic applied to the output of programs while debugging such that if a program writes to the console (as a result of an error, assert) something like:
/Users/Foo/Project/SomeFile.m:12 - SOMETHING BAD HAPPENED HERE
the file path & line name are automatically detected as link to source, and one can click or double click on the text in question inside the console window to make the source editor jump here.
I have been trying to find out if XCode has something similar, but I haven't had much luck. Is any such functionality missing in XCode or am I just not finding the preferred text shape that it prefers?
Thanks

I just remembered "Open Quickly…". If you copy the text of the file name, then use the "Open Quickly…" function (Cmd-Shift-O by default), you can paste the filename in and press enter, and it will display the file.

Related

Read current terminal

Is it possible to read what's currently displayed on the windows terminal pragmatically using any available API?
For example, I've got an app that tail's some log files. I'd like to be able to hit a key and open a text editor at the line that is currently being viewed. The problem is the terminal also has scroll bars.
Not easy. Perhaps you could capture the screen and use OCR to identify its contents, or make a shortcut to some sort of macro that selects all the screen and copies the text. But there is no API available to perform the task you ask.
Of course, you can tee the command you're running in the console to a file, and open such file with an editor whenever you like, however it will show the full output of the command and not the visible part. If you like more information on that topic, it is answered in SO - Displaying Windows command prompt output and redirecting it to a file
.

Automator "Output replaces selected text" not working

I am trying to write an Automator script, that replaces a given text by some other text. I followed the steps in
Editing text in Automator
which are the same as given by a bunch of blog posts covering this topic and may vary with regards to the language the script is written in. I tried with AppleScript and with bash.
My (reduced example) bash script is:
echo hello
I have selected the option "Output replaces selected text".
I tried the script when selecting text in Xcode, TextEdit and another app. The text is not replaced (it remains the same). The script is executed - as I tested via say hello inside of the script. Also I followed the setup of:
http://www.kevincallahan.org/software/services.html
to make sure my script is enabled in "System Preferences -> Keyboard -> Shortcuts -> Services -> [√] myService", because this tool used to work on my machine and it should have the same requirements for replacing text inside a TextView like the script I am going to write. Also I read the answer:
Automator not working inside xcode
from which I could not deduct, what "give xcode access to be able to modify accessibility settings" means. I am running macOS 10.13.4.
I finally figured something out. After creating a copy of the script in the file system, the copy worked. The only difference was the name. Indeed, if I renamed the original script, it worked. The name was "resolveConflicts". I have no app in my PATH with the same name. The only place I used the same name was inside SourceTree -> Preferences -> Custom Actions. Renaming the action in SourceTree did not allow me to successfully run the script with the name "resolveConflicts". In the end I could not figure out, with which name the scripts collided. I also checked /System/Library/Services and /System/Services. No scripts with same name existed there. I sticked with a different name.

Is there a way I can edit or rewrite default Matlab Apps?

Is there a way I can edit or rewrite default Matlab Apps such as "Image Viewer?"
Matlab R2016b
The Image Viewer App is called from the command line as imtool. You can open this file in the Editor using edit like so:
edit imtool
or you can find its location with which and open it in whatever other editor you like:
>> which imtool
C:\Program Files\MATLAB\R2016b\toolbox\images\imuitools\imtool.m
If you really want to modify it, I suggest making a copy of your own and renaming it, leaving the built-in one unchanged and still available.
For other apps, if you go to the "APPS" tab and pull down the menu it will list all the built-in ones available:
Notice that hovering over an app will give a brief description with an associated function name in parentheses. For example, the Video Viewer App can be called with the function implay.

Keep focus in command window when debugging MATLAB

Often in MATLAB I turn on 'automatic' debugging with dbstop if error. When an error occurs, the function enters debug mode, and I am able to query the variables in the command window and see exactly what is going on. Very useful.
However, when this occurs, the focus switches to the editor. To me this seems counter-intuitive; we are in debug mode, so I want to find out what is going on, not look at the code (which I can already see in the adjacent window). I always immediately tab back to the command window.
So my first question is: Is there any point in accessing the editor at this point? What can I usefully do, when my script has crashed, in the editor?
And secondly: If I want to, can I change MATLAB's default behaviour to keep the focus in the command window?
To your second question:
If you use MATLAB's desktop environment, just deselect "Open Files when Debugging" in the "Debug" menu.
If you use MATLAB without the graphical desktop you can change this preference by modifying your matlab.prf file. This file stores preferences set from the GUI. The menu option described above makes the same changes as the manual process described below.
NOTE: Editing this file is entirely unsupported. Do so at your own risk.
Open the file from the MATLAB command prompt,
>> edit([prefdir '/matlab.prf'])
Or use the prefdir command in MATLAB to find the directory and then open the file in whatever editor you prefer.
Search for a line that says
EditorGraphicalDebugging=Btrue
Change it to read
EditorGraphicalDebugging=Bfalse
If the line doesn't exist, add it to the file.
Restart MATLAB.
You can use the invocation stack to see how you came about to the particular error position. Sure, you can use dbup and dbdown for this in the command window, but it's much easier in the editor.
Also, seeing the variables (and their values, using mouse hover) in the context of the code that caused the crash is far better for understanding the root cause of the error than just seeing the static values.
I can answer only your first question.
Things you can do in the editor:
Mouse hover a variable, which pops up a 'quick view' window.
Any action you can do when not in debug mode, treating the function as a script - running a line (highlight + F9), running a code block, etc.

Textmate, open file at Caret

I bet this is really obvious but I can't find how to open the linked file that the Caret is currently on in Textmate. For example in the likes of Dreamweaver you can click in the index.html portion of <a href"index.html" hit cmd-D and it opens this file in a new tab. Is this possible?
Would also be good to do this with <img src="image.jpg" to open the file directly into Photoshop.
Solved!
Solution for Patrick below.
I used a modified version of Daustin777's example above to create a Command called OpenatCaret.
The command is: open "$TM_PROJECT_DIRECTORY"/"$TM_SELECTED_TEXT"
I then extended this by installing a macro which allowed you to select a path between double quotes but not including the quotes. I got this from the macromates board here. http://lists.macromates.com/textmate/2009-June/028965.html
To wrap them both together I put my cursor in a path and recorded a new macro where I run the "Select within double quotes" macro and then the OpenatCaret command. I then named this OpenProjectFileAtCaret and bound this macro to cmd-D.
Works a treat and is used all the time. Just make sure you have the correct default apps setup for each file type you are opening eg. Textmate for php, asp, html and it will open them in a new tab.
I don't have a full solution as a linked bundle but this should get you close.
You can use the Bundle Editor to create a command that will open an image if you select the path. Create a new command and enter this:
open "$TM_DIRECTORY"/"$TM_SELECTED_TEXT"
Set Input to Selected Text or Word Set Output to Discard Set Key Equivalent to an unused key combination.
Close the editor. Now you should be able to select an image path and it will open when you press the appropriate keyboard shortcut.
You can add the -a flag to the open command to specify which application to use to open the selected file. This is just a basic example and not an entire solution that will work with every type of file path.
You can get info on Textmate environment variables here.

Resources