Parallel processing 2 scripts

Hi,

Does anyone know when you run two process in unix, do they run almost simultaneously. For example, the following script runs two processes:

set script1 to quoted form of "delay 1
return 1"
set script2 to quoted form of "say \"Hello\" without waiting until completion
return 2"
do shell script "(osascript -e " & script1 & " & osascript -e " & script2 & ")"

Edited: should have said in almost parallel.

Edited: Narrowed it down to about 0.085 secs for the say command. Don’t know how accurate this is:

set script1 to quoted form of "delay .084
return 1"
set script2 to quoted form of "say \"Hello\" without waiting until completion
return 2"
do shell script "(osascript -e " & script1 & " & osascript -e " & script2 & ")"

Edited: about 0.087 might be better.

Thanks,
kel

Only one say command is being called at a time – it’s just that the command you’re calling is asynchronous. Whether you can do that depends a lot on what you are actually doing. I’m not sure what you mean about two processes in unix – we’d be in trouble if it couldn’t happen…

Hi Shane,

That’s true. It surprised me when the say command took that long (0.087) without waiting. Seems like somethings wrong. there.

Later,
kel

Oh, I think I know. The ‘say’ command is carbon right?

Not necessarily – they might be using NSSpeechSynthesizer. It probably takes a relatively long time to initialise one.

So today I can post what I wanted to post the other day. This requires 10.9. Save the following script as a .scptd bundle in ~/Library/Script Libraries/ (you will probably have to make the folder). When you have saved it from ASE, click on the Bundle Contents button in the toolbar, and check the AppleScript/Objective-C Library button. Save.

use AppleScript version "2.3"
use scripting additions
use framework "Foundation"
use framework "AppKit" -- for NSSpeechSynthesizer

property theSender : missing value

on startSaying:theString sender:sender
	set my theSender to sender -- store in property for later use
	set theSynth to current application's NSSpeechSynthesizer's new()
	theSynth's setDelegate:me
	theSynth's startSpeakingString:theString
end startSaying:sender:

-- delegate methods
on speechSynthesizer:anNSSpeechSynthesizer willSpeakWord:anNSRange ofString:aString
	log (aString's substringWithRange:anNSRange) as text
end speechSynthesizer:willSpeakWord:ofString:

on speechSynthesizer:anNSSpeechSynthesizer didFinishSpeaking:theFlag
	theSender's stringSpoken:(theFlag as integer)
end speechSynthesizer:didFinishSpeaking:

Now open a new script window, and enter this, changing the script name to the name of the file you just saved (without extension):

use theLib : script "<script filename>" 
use scripting additions

theLib's startSaying:"Hello world, welcome to AppleScriptObjC" sender:me

on stringSpoken:theFlag
	if theFlag = 1 then
		log "The string was spoken"
	else
		log "Trouble at mill"
	end if
end stringSpoken:

Hit run and look at the log.

Hi Shane,

Great! I was planning to get Maverick once I figure out a safe way to make payments on the internet. I used to use credit cards, but don’t want to do that now.

Thanks,
kel

Well given it’s a free upgrade…

Alright! I didn’t know that. :smiley:

Thanks,
kel

Christmas came early. Nice Santa! :slight_smile:

What did I say the other day in another thread?

Bingo, we have a winner…

:wink:

Sometimes things that are too good to be true, happens to be true! :slight_smile:

Not that that happens too often. I have read the review at Ars and free is of course very good, but this version has a lot more qualities too it than just being free. As I see it, the whole thing is a big leap in the right direction.

The only thing missing, is the ability to add applets to all window toolbars in all programs!

Thank You Apple!

I am seriously considering an Apple tattoo. :slight_smile:

McUsr, you’re funny. Apple tattoo, hahahahaha. =))

:lol:

I’d say that the Apple Logo is one of the more meaningful tattoo’s in the world. (It looks nice too.)

Yes, the apple does look good. Me, I’ll need to get a pineApple tattoo!. :slight_smile:

I have to wait until tonight to update to Maverick. :frowning: The wifi might be too slow during the day and evening. Still need to plan how to backup all the files anyway. Then, I can try Shane’s script. Can’t wait to try Maverick. I wonder if Maverick fixes the slowness in Civ 5.

Hi,

Seems like the same system until now.

Now I can run Shane’s script. can’t understand what will happen until I run it.

I just thought of something. The different OSX version is like an upgrade and not a new OS.

Anyway thanks Shane for the start in this new system,
kel

I read that somewhere, where they said that the underscore was being replaced by the colon.

Man, I’m loving this system so far.

I decided that I’d finish a project first, since I’m not sure the tools will continue to work in the beginning.

But I wonder: Did you install it right on top of your old system? (Or, how did you install it?)

Thanks.

:slight_smile: