Well I found a nice tutorial about how to program applications using Bonjour. It's cool. But the only problem, I do not understand which language they teach. I am not even sure that it is a programming language? May be they write about commands that should be typed in a command line? Or may be these are commands which should be executed in some GUI applications? Somehow I cannot find the context in which this tutorial is given. It is strange to me that they do not write what is that.
Can somebody resolve this mystery?
Its the C API for apple's Bonjour services; this is hardly a programming tutorial.
Looking at the left, there's a block that says:
RELATED REFERENCE
PROCEDURAL C DNS
Service Discovery C Reference
I'm going to go out on a limb and say it's probably C.
From the URL, title, and menu you can tell that it's a article about registering services using their dns_discovery_api in C.
This is not a programming tutorial.
That’s not a tutorial about how to program, OS X programs are written in Objective-C (although this is a C API), and that page has a table of contents on the left side.
The mDNS command line tool can be used to test Bonjour services.
Related
I've created an application in the past, in Lazarus Pascal, which execute "dd" to write an image to a drive. For this, obviously, elevated rights are needed.
In the initial version I have used AuthorizationExecuteWithPrivileges() (link), even though not exactly intended for this purpose, it did work very well and very consistently.
This function however has been depreciated since OSX 10.7, as it can be a security issue, and command line statements that redirect do not work properly either (redirecting output from zip as input for dd).
In the next version I've used a method described in the Lazarus Pascal Wiki (Executing External Programs), which basically starts a TProcess which my program communicates with. Using sudo -S dd ..., the users password is asked and entered to make sure he/she has the proper access rights.
Obviously a little bit of a dirty hack method, and it shows, certain users experience issues with this.
After doing a lot of reading, it seems Apple prefers this to be done with a helper tool called SMJobBless(). I'm unfortunately not very experienced when it comes to Objective-C, the presented code seems very minimal at best and not very well documented either.
I was wondering if anyone has experience or could assist in "porting" this method to Lazarus Pascal ... I'm all in favor of doing it right.
Alternative methods are most welcome as well of course!
Any help would be greatly appreciated.
I'm unfortunately not very experienced when it comes to Objective-C
Don't let this put you off from using the example provided by Apple. If you look closely at the code in SMJobBlessAppController.m, you'll see that other than one line of Objective-C code, the rest is simply C.
The Objective-C line registers the helper application: -
if (![self blessHelperWithLabel:#"com.apple.bsd.SMJobBlessHelper" error:&error])
You'd use your own URI, instead of com.apple.bsd.SMJobBlessHelper.
All the other relevant lines are plain C functions. Breaking this down, you're left with: -
// Obtain rights
AuthorizationCopyRights(self->_authRef, &authRights, kAuthorizationEmptyEnvironment, flags, NULL)
//Start the helper
SMJobBless(kSMDomainSystemLaunchd, (CFStringRef)label, self->_authRef, &cfError);
I've left out checking for error codes, but I hope this has shown just how little code you need to work with and very little Objective-C knowledge is required.
Since it took me a lot of work and figured it would be helpful to others, here my final working solution.
https://www.tweaking4all.com/software-development/lazarus-development/macos-smjobbless-elevated-privileges-lazarus-pascal/
You'll find there an example project and tons of info.
The steps to reproduce this are quite extensive, so here a short recap:
I've been using CFMessages to send messages to the Helper Tool since I had no bindings for NSXPCConnection.
The Helper Tool has to be based on the Lazarus Pascal template "program" or "simple program", and cannot based on any of the TApplication classes, and cannot create any treads.
For the Helper Tool, one needs to create a info.plist and a launchd.plist, which both must be embedded into the binary.
The Main (test) Application can be any Lazarus Pascal application, but needs a proper Info.plist as well, indicating that the Helper Tool is allowed to start with elevated privileges.
The Helper Tool and the application app bundle both need to be signed with a valid Apple Developer ID.
Some missing bindings need to be put in place:
const kSMRightBlessPrivilegedHelper = 'com.apple.ServiceManagement.blesshelper';
function SMJobBless(domain:CFStringRef; executableLabel:CFStringRef; auth:AuthorizationRef; outError:CFErrorRef): boolean; external name '_SMJobBless'; mwpascal;
var kSMDomainSystemLaunchd: CFStringRef; external name '_kSMDomainSystemLaunchd';
And the proper frameworks needs to be included:
{$linkframework ServiceManagement}
{$linkframework Security}
{$linkframework Foundation}
{$linkframework CoreFoundation}
{$calling mwpascal}
And let's not forget to set callback function to handle incoming messages.
I hope this is useful to someone ... :-)
Heres my problem, I'm web developer and I have a web based script(PHP/CURL/HTML/JS) that gets latest threads from forums with job listings, however right now I have it email me when a new one is made, what I'd like to have is some sort of an app, basic idea would be a browser type app, where it would load in the url, and then html/css would do the rest, refresh every X seconds, play sound if there is a new thread, etc. (however I don't want to just have a tab open, I'd liek it to be a seperate app, I know this is rather easy in VB on windows)
What language would this be coded in and does anyone have any starting points? I have basic experience in VB, but thats about it as far as programming software languages.
Eventually I'd like to make this into an API with the program requesting XML from server and then style it from there, as well as functions such as contact the thread poster etc(but this will require a lot more experience from my end in order to design the functions that could call to the server with all of the parameters etc)
Any ideas would be appreciated!
Have a look at RealStudio. It's very easy to use and should be familiar, given your VB experience.
The standard language for use on OS X is objective-c. However this has quite a steep learning curve. It is possible to use C# on OS X using Mono, but I have no experience with that.
I would suggest using XCode and Objective-C given that you are targeting OS X. This should be rather simple using the WebView. See here for a tutorial.
Can somebody please guide me in the right direction of creating a scripting language that targets the WSH (Windows Scripting Host)?
I have googled for it, but there seem to be far fewer links related to this than when I originally searched for it a few months back.
THank you
The product is now called "Windows Script Host". The MSDN documentation suggests that what you want is a Windows Script Engine, about which the documentation claims that you can create one for any programming language or environment—presumably including one you create yourself. Beyond that, the documentation is not terribly clear.
You should be able to find all necessary information about creating Windows Script engines on MSDN; other than that there seems to be no resources available (at least I couldn't find any). You can also take a look at some open-source engine implementations to get the idea of what your code should look like:
PHPScript
ActiveScriptRuby
Open Object Rexx
If you have any specific questions about implementing Windows Script interfaces, feel free to ask them here. Good luck!
Topic starter need to carefully read the script56.chm, which can be found on MSDN. This help file describes WSH engine specification.
I need to write a daemon, much like windows service on os x using objective c.
Can anyone point to some sample? or guide me about how to do this?
There is a complete technical note available on the Apple Developer site.
You will find all the needed information, as well as the restrictions for creating, launching and debugging a daemon, whatever its language.
See also this entry on SO.
OK,
I want to create a windows shell extention that sits in the file menu much like the "Tortorise SVN" menu.
Does anyone know where I'd begin, a good article, or what interfaces to implement?
Thanks!
It's pretty straight forward actually. It's about a 3-4 step process. You didn't specify what language you were using.
Here's how to do it in native code:
http://www.kbcafe.com/articles/HowTo.Shell.pdf
Here's how to do it with .NET. Note that it is essentially the same as doing it with native code.
http://www.theserverside.net/tt/articles/showarticle.tss?id=ShellExtensions
Ah... Shell extensions... they can be a real pain in the butt if they're complicated, but you can do so much neat stuff. A great place to start is Mike Dunn's Complete Idiot's Guide To Writing Shell Extensions on codeproject.com.
There's an O'Reilly book called VB Shell Programming which goes into the API's in some depth. As the title suggests, it's aimed at Visual BASIC, but the API's are exposed through COM and the techniques discussed in the book are applicable for pretty much anything that supports COM. A quick look on Amazon.com suggests you can probably pick up a secondhand copy for a few dollars.
Avoid codeproject (for kids, full of bugs) and read the complete doc of MSDN on SNE.