In former OS X versions (pre 10.6) it was possible to call Cocoa methods via the "call method" command in applescript ("Applescript Studio").
E.g. this way:
set theURL to "http://www.apple.com"
set URLWithString to (call method "stringByAddingPercentEscapesUsingEncoding:" of theURL with parameter 30)
The script interpreter in the "Applescript Editor" (10.6) does not understand the command "call method". - Is there an equivalent for "Applescript Editor" (10.6)?
You can use "call method" in applescript. Apple gave that ability to Automator and we can access that ability from applescript by using the "Automator Runner" application. I just showed this to someone recently. See my post #4 here.
So to answer your question, just put your "call method" code inside a tell application "Automator Runner" tell block.
AppleScript Studio I thought was done in Xcode not AppleScript Editor. Code in AppleScript Editor can only be saved as scripts and the language is just plain AppleScript.
If you're doing this is Xcode, on 10.6, AppleScript Studio no longer exists. It's now AppleScript-Obj-C
I don't know an exact answer.. but...
If you take - (void)makeKeyAndOrderFront:(id)sender in AppleScript-Obj-C, if I have a property linked to a window in Xcode I just go: myWindowProperty's makeKeyAndOrderFront_(sender)
I hope this helped at least a bit!
Related
Aside from the generator for a struct's memberwise initilizer, does Xcode have a "Generate Initializer" command similar to IntelliJ's "Generate Constructor"? If not, is there a way to make one? I'm looking to speed up my dev process a bit.
I'm not sure if this works in objective-c, but this works in Xcode with swift. If you right-click on the class name in its declaration, you can select refactor->generate memberwise initializer.
For Objective-C, just type init on a blank line somewhere at file scope within the #implementation and the autocomplete menu will offer some ready-made init method snippets. (This is just Xcode's general code snippets functionality. You can create your own snippets to work just like that.)
I am learning Objective-C and using this tutorial. It says I am supposed to create a Command Line Tool. However, the XCode version in the tutorial is rather old. Pressing CMD + N does not reveal a Command Line Tool option. How can I write Objective-C and compile and run it in XCode 9.2?
Have a look #Stophface
If you are on mac then it says you should press cmd+shift+N
try it
You have chosen the iOS category at the top, click on macOS and it should be there.
this question is several months old, but for other people here is an answer :
You need to download an additional element : "Command line tools for Xcode"
link : https://developer.apple.com/download/more/
You need to create a free account, just with your email.
There are several versions, check which version of Xcode you have. Once it's installed if you click on "new project" you will have access to "command line" options
Is it possible to call an Objective-c class from AppleScript in OSX 10.7?
I have seen some suggestions for Snow Leopard or earlier, but none seem to work.
AppleScript-Obj-C seems to be a way of constructing a GUI which uses AppleScript, but I want to call a class I have written from a script.
The following (which does not work) is what I would like to do:-
on getJpegComment(photoFile)
set aJpeg to call method "initWithPath" of class "JpegCom" with parameter photoFile (does not work)
return call method "comment" of aJpeg
end getJpegComment
tell application "iPhoto"
tell album "Sale"
set thePhotos to get every photo
end tell
repeat with aPhoto in thePhotos
tell application "iPhoto"
set aPhotoFile to image path of aPhoto
set aComment to my getJpegComment(aPhotoFile)
set comment of aPhoto to aComment
end tell
end repeat
end tell
I started down this path because of links which seemed to indicate this was possible.
I could write an Objective-c program, which called AppleScript, but this seems overkill for seemed to be a simple task.
PS I have thousands of photos, which I had entered JPEG COMments of Windows, unfortunately iPhoto does not understand these.
When I want to do a simple task like you, and I need something from objective-c, I find the easiest solution is to turn the objective-c part into a command line tool in Xcode. Then I call the tool from applesript using "do shell script". I have many examples of these tools on my website of 1) the code for the unix tool, and 2) how to use the tool from applescript. So basically you make a tool which accepts one parameter (eg. the path to the image) and it returns the comment. Look here for my tool examples. Any of the items under the "Code Sharing" menu will help you with this approach.
No, you can't call Objective-C from a regular, freestanding AppleScript run from AppleScript Editor or a script menu. You would need to build your script into an AppleScriptObjC application created with Xcode or execute it in a special environment such as ASObjC Runner.
For cases where I just want to call a couple Objective-C methods, I would probably use do shell script to invoke Python and use the PyObjC bridge. That way your script remains compatible with regular AppleScript, and you don't need any auxiliary executable files. For example:
do shell script "python -c 'from Foundation import NSDate; print NSDate.date()'"
You can make an AppleScriptObjC script using AppleScript Editor. Go to File > New from Template > Cocoa-AppleScript Applet.
This will run like a standard script, without any GUI, but you can also access Cocoa functionality like you can when using AppleScriptObjC in Xcode. You should also be able to use Objective-C classes like you would do in Xcode.
is there already any IDE / tools that if you highlight a function name, it will open the file where that function is defined on the next window so we could understaand what that function does?
you know just wondering.
Visual Studio has a "Go To Definition" feature available in its text editor. When the cursor is on a varible, function, class, and so on, you can right-click and select the "Go To Definition" menu item and it will take you to where the function is defined. If the definition is part of the .NET Framework, the feature will "jump" to the definition in the Object Browser for VB.NET projects or to the "meta-data" of C# projects
Are there any IDEs that don't do this? Every IDE I have ever used had this feature: several Smalltalk IDEs, Hopscotch, several Lisp IDEs, NetBeans, Eclipse, Visual Studio, VisualAge for Java Micro Edition, VisualAge for Java, VisualAge for Smalltalk. Even many text editors can do it: TextMate, Vim, Emacs, Notepad++.
By using something like ctags this is definitely possible, provided of course your favourite editor also has support for ctags. The good thing about ctags is that with a bit of tweaking it can be made to work with almost any language.
In Netbeans you highlight the function -> right button click -> Navigate -> Go To Declaration and it will open the file where this function has been created.
I use Eclipse as my Java IDE and find the F3 key to be the quickest way to open the declaration. Good description of this functionality below (from here):
F3: Open declaration. Alternatively,
you can click on the Declaration tab
(in the Java perspective, go to
Window, then Show View, then
Declaration). This key shows entire
method declarations in the declaration
pane when you click on a method call
in the code.
I haven't used this with other languages editors in Eclipse (Perspectives in Eclipse), but I'd guess the functionality is similar.
I'm trying to watch a variable with Xcode. I'm following the instructions in here by pausing at a breakpoint, selecting Run > Variables View > .... but with the exception of "Enable Data Formatters" the rest of the options are all greyed out. Any ideas?
I'm using Xcode version 3.1.3.
I haven't gotten watchpoints created from the Run menu to work for me either, unfortunately. One thing to be aware of is that when a variable goes out of scope, the watchpoint may become invalid.
If you don't mind getting a little more in-depth, you can use some low-level gdb commands to set a watchpoint for the address of the memory itself. For example, in the guide you linked to, they show how to watch the variable path which is a pointer with the value 0xbfffeb70. To manually set a watchpoint for that address, click in the debugger console (where the debugging output is printed) after the "(gdb)" prompt and type something like this:
watch *((int*)0xbfffeb70)
The cryptic syntax is necessary because gdb expects inputs as C expressions. For a little more detail, visit this link and jump to the section titled "Using hardware watchpoints". (I'm testing on an Intel machine, not sure how PowerPC handles it.) When you set watchpoints this way, Xcode will alert you with a drop-down sheet when a watchpoint is reached and tell you how the value was changed, and gdb will print the same info in the console.
I just ran into this problem. Here is a solution: right click on the variable name and select "View variable in window" from the menu which appears. It should be near the bottom.
Add a breakpoint. Right click in the watch list of the debug area and choose "Add expression..."
If you are getting a different menu, you have to click off of the currently highlighted variable so that nothing is highlighted when you right click.
The Answers given here only work if you use the gdb compiler. For those of you who are looking for an option to set a watchpoint with the lldb compiler I have bad news:
It's not working jet (XCode 4.3.2 with lldb 3.1) even though the lldb docs say you can.
Check out this Email. The lldb commands compared to the gdbs can be found here
I was trying to figure this out in XCode 5. I finally found a "Variables view" button at the bottom right of the output console. It's the little rectangle that will be gray on the left, white on the right if it's not enabled. I'm not sure if this is in XCode 3, but I expect most people have upgraded anyway.