ScriptingAddition vs Application

I agree, but it gets the job done. The sole reason for the utility, is to avoid AppleEvents when say checking for aliases in a deep folder structure. So the system is responsive to more important AppleEvents. Some smart guy has told me that do shell script uses zip AppleEvents. :slight_smile:

Edit
Now it works with filenames consisting of one character…:mad:

By the way, I came over some interesting tools for handling extended file attributes, while looking for examples in XCode, the FSEx example files ->filesystem_examples.zip contains three commands for modifying and looking at extended attributes.

You can also use isalis to cd into aliased directories with, with the shell function below, that should be saved into your .bashrc file.

function cd { if [ ${#1} == 0 ]; then builtin cd elif [ -d "${1}" ]; then builtin cd "${1}" elif [[ -f "${1}" || -L "${1}" ]]; then path=$(isalis "$1") builtin cd "$path" else builtin cd "${1}" fi }
I found the original here.

Hello Shane

What to do when Apple itself continue to call tools deprecated, sometimes for years ?

Here are some example borrowed from the console :

21/05/2013 13:48:21,719 AppleScript Runner[12240]: CPSGetFrontProcess(): This call is deprecated and should not be called anymore.

Desktop & ScreenSaver :
21/05/2013 16:19:28,967 System Preferences[13114]: *** WARNING: -[NSImage compositeToPoint:operation:] is deprecated in MacOSX 10.8 and later. Please use -[NSImage drawAtPoint:fromRect:operation:fraction:] instead.

Restart Prefpane :
21/05/2013 16:20:31,136 System Preferences[13114]: *** WARNING: -[NSImage dissolveToPoint:fraction:] is deprecated in MacOSX 10.8 and later. Please use -[NSImage drawAtPoint:fromRect:operation:fraction:] instead.

Disk Utility (when triggering Partition tab) :
21/05/2013 16:21:34,295 Disk Utility[13142]: *** WARNING: -[NSImage compositeToPoint:operation:] is deprecated in MacOSX 10.8 and later. Please use -[NSImage drawAtPoint:fromRect:operation:fraction:] instead.

Is is required to send a mail to Craig Federighi ?

KOENIG Yvan (VALLAURIS, France) mardi 21 mai 2013 16:25:30

Hello.

I was sure I was in the clear on this, but okaay. I have figured out I can mend it with a toll-free bridged NSUrl…

The tool isn’t quick and dirty anymore, just a reflection. :slight_smile:

That depends. If you’re feeling energetic you can report them, but unless they’re AS-related there’s probably not a lot of point.

But keep in mind that there’s nothing wrong with using something deprecated in 10.8 under 10.8. To that extent, deprecation is a warning, or a statement of intent. Something can even be marked as deprecated before an alternative is supplied. There are quite a lot of such things in 10.8. It’s using them a version later that can be risky. Even then, Apple engineers are obviously better placed than others to know what the risks are.

Deprecations in AppleScript are a bit different. Given its audience, a longer life after deprecation is to be hoped for, if not expected.

(In case it wasn’t obvious, I was teasing MacUser.)

Thanks for that, I have just read from page 91 or so in “FileSystemProgrammingGuide” (most interesting, and definitive about the various file system attributes ). I’m going to learn a little bit of this, so keep on teasing.

I like to get the big picture before I program, so don’t hold your breath. :slight_smile:

So let’s try to bring this back on topic. Paste this into a new Cocoa-AppleScript document in AppleScript Editor and run it. The lines commented with a # are the Objective-C equivalent, for MacUser’s benefit:

set thePath to POSIX path of (choose file with prompt "Choose an alias:")
-- make a URL from path
# NSURL *theURL = [NSURL fileURLWithPath:thePath];
set theURL to current application's NSURL's fileURLWithPath_(thePath)
-- check it's an alias/bookmark
# NSNumber *theValue;
# BOOL theResult = [theURL getResourceValue:&theValue forKey:NSURLIsAliasFileKey error:NULL];
set {theResult, theValue} to theURL's getResourceValue_forKey_error_(reference, current application's NSURLIsAliasFileKey, missing value)
# if (theResult && [theValue boolValue]) {
if theResult as boolean is true and theValue as boolean is true then
	-- get bookmark data
	# NSData *theData = [NSURL bookmarkDataWithContentsOfURL:theURL error:NULL];
	set theData to current application's NSURL's bookmarkDataWithContentsOfURL_error_(theURL, missing value)
	-- get path from data
	# NSDictionary *theDict = [NSURL resourceValuesForKeys:[NSArray arrayWithObject:NSURLPathKey] fromBookmarkData:theData];
	set theDict to current application's NSURL's resourceValuesForKeys_fromBookmarkData_({current application's NSURLPathKey}, theData)
	# NSString *thePath = [theDict valueForKey: NSURLPathKey];
	set thePath to theDict's valueForKey_(current application's NSURLPathKey) as text
	display dialog "The original path is at " & thePath
else
	display dialog "The file was not an alias." buttons {"OK"}
end if
tell me to quit

Quick, not quite so dirty.

And enough money to be able to enjoy it. :wink:

Indeed!

Agreed. :slight_smile:

Thanks for the example Shane, that is quicker, and not so dirty. And a great example, with the missing pieces!

I’ll come back when the ground is fully covered. I also found a great example in DisplayURL by the way, but I am not finished with the rfc yet. At least Apple doesn’t write the most boring documentation. (I am not thinking of the rfc, it is clear and concise.)

If they don’t show up in Script Debugger that doesn’t mean they aren’t there… Even do shell script uses Apple Events.

I think Script Debugger shows the events correctly, insofar as it shows events that are passed back and forth between your script/applet/whatever and “something” that handles events runtime.

I agree there must be some kind of event, or construct that takes place behind the scene, but that is not an IPC event reaching outside the scope of whatever you have running. So those doesn’t count as events that is sent out of whatever, while the do shell script is run, unless you call an osa script from within the do shell script.

Maybe compile-time binding event, would be the right way to describe it? i don’t know.

The do shell script, sets up a pseudo terminal, and executes whatever it has been given blindly, it returns with output produced, and an exit code.

According to my Apple Event manager it sends an event but without an target application. The event is named syso/exec if you want to know. It just has no target application like most Apple Events but it is still handled by the event manager, as the debugger shows in Snow Leopard. I don’t have Script Debugger and I assumed that the event didn’t show up in there.

Hello.

Where did you get/find that AppleEvent Manager? :slight_smile:

It is interesting to know about that/such kind of events, and I believe that event to be the event that fires off the do shell script command, I bet delay and other commands have similiar events, and the fact that they aren’t resolved, is because they are executed within the current AppleScript Environment. With the latter (Environment) I mean within the context of your running script. And since it then is within the context of your running script, it is internal, it is not reaching out for another independent process.

Edit
I don’t care really if the delay command is in a Scripting Addition, and really fires off an external apple event, in this context, it was the closest to an internal command that I could think of when I wrote the post.

By the way, interesting algorithms for both resolving paths, and creating regexps for tearing them down in rfc3986.

And what I gather as the single most useful thing with the do shell script, is the “with administrative privileges”, which is a huge boon when it comes to security, as it enables you to do whater admin task you need to do without switching account, or having your account set up as an administrator command.

While I am at the do shell script: I believe the commandline that is sent to the do shell script to be parsed, before that syso/exec event is sent.

And the do shell script “blocks” until whatever is processing is finished, as long as the output of the do shell script is redirected to /dev/null or similiar. The reason for this, is that when the pty are set up and the commands are sent to sh, the pty part of it, realizes that there isn’t any output to be waited for and returns. So, if you do this, and tells your command to execute in the background, then you have effectively created a thread of execution, that executes in parallell with your main script. Now, a maybe interesting little tidbit: if you are trying to create a new session in a an Os X terminal window, (maybe for interactive processing or what not), in order to set up a new controlling terminal for a process group, then you have to acquiere/use a pty, in order to get that new terminal, everything else is futile. That isn’t documented anywhere, but my experience is that using a pseudo terminal isn’t an optional step.

Technical Note 2124 in section “Apple Events”

Make sure script editor is not already running and then In terminal type:

$ export AEDebugSends=1 $ export AEDebugReceives=1 $ /Applications/Utilities/AppleScript\ Editor.app/Contents/MacOS/AppleScript\ Editor &
Keep the terminal window open, every Apple Event that will be send and received between Script Editor and the Apple Event Manager will be logged in this window. As you can see, do shell scripts will be passed too :D.

FYI: delay command doesn’t send an Apple Event.

:smiley:
Thanks for sharing!

I was pretty confident, that the delay command would behave like a do shell script, since it works everywhere, and is part of the standardAdditions.osax. That it doesn’t send any event at all, puzzles me.

Hi,

As I remember, I could never get the ‘delay’ command as data. If you compile a script, then take the scripting addition out of the system, you should get the data, I think. I’m not trying it. Where’s Mikey? :slight_smile:

Editted: I have scripts running with delays.

Hello.

I am done with the pure coreFoundation tool in post #33. Not so quick, maybe still dirty.

But I have added a usage function. And for the record, CoreFoundation must be one of the best C-Libraries ever written, not that you should reach that conclusion by reading my code. But it feels veeery good, solid and stable, well documented too. It is a pleasure! :smiley:

Edit

Now releases all memory previously allocated. Don’t know if it is any point, but if you loop over some files, the kernel may not release quickly enough.

Ok.

So I made a real command out of isalis, so that you can either give arguments on the commandline, or pipe a file list to it, and get a list of either any aliased files, with any broken, or just broken, or just aliases, so that it is usable in various ways, and not for just being able to cd into an aliased directory, nor only workable with the find command.

Just type isalis for command line help.

It can be found here, with sourcecode included

Edit
Freed a buffer I had forgotten to free.

And accurate help! :slight_smile:

I don’t follow your memory management, but this:

will amount to passing NULL to CFRelease() if err != noErr, which will cause it to crash.

Thanks, for pointing that out.

It is fixed, I’ll upload the fix as soon as I have fixed another issue, (if it wasn’t that one).