THTask (NEW)

Here is where the magnanimous folks that create externals post them (.zip archives only please).

THTask (NEW)

Postby sctell » Fri Jun 17, 2011 6:31 am

Hi,

Due to the other THTask thread becoming a bit of a mess, as a result of me trying different things in relation to running multiple tasks I have started this new thread and asked Scott to delete the other.

It is my intention to stay on topic in relation to the functions below.

I think (famous last words) that I may have cracked it but it has involved me going back to basics.

The functions available are:

put THTask("launch",tCommand) into gTaskID
get THTask("suspend",gTaskID)
get THTask("resume",gTaskID)
get THTask("interrupt",gTaskID)
get THTask("release",tTaskID)

The result of a launch or interrupt is handled as follows:

A cd message is sent, "taskOutputData"
The result is placed in a global variable gTaskOutputData
The first line of gTaskOutputData contains the taskID

You must "release" the task when it has finished.
Last edited by sctell on Fri Jul 22, 2011 10:56 pm, edited 3 times in total.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THTask (NEW)

Postby johnjohnston1 » Fri Jun 17, 2011 10:09 am

Hi Terry,
nice.
I put the urls to a couple of ~25mb m4v files into the bottom button script
started some music with the Example 3 button, then hit the 3 task button.
Music didn't blink, just kept running as the movies downloaded.

I do see some beachballing if I go the other way, start the download and then play some music but that is probably a silly thing to do;-)

thanks again

John
User avatar
johnjohnston1
 
Posts: 196
Joined: Sun Jul 06, 2008 10:42 am
Location: Glasgow, UK

Re: THTask (NEW)

Postby sctell » Fri Jun 17, 2011 11:59 pm

Hi,

I forgot to mention one of the functions available

put THTask("isRunning",tTaskID) into tRunning

Sometimes if a task takes a while and you repeatedly call the same programme as you may do with the script below to sqlite3 say

addRecord...
addRecord...
addRecord...

etc

Supercard has called the next addRecord before the other has finished the result being confusion for sqlite3 and lost data.

Where you have this situation you should sacrifice working with tasks in parallel and use something like the repeat while loop below.

An added benefit of the repeat while loop:

I have noticed that if you use get shell(), the native SC function, with a shell command that will take a long time to execute you get the dreaded beachball and SC not responding showing up at various places in OSX.

If you you use the repeat loop arrangement below the beachball does not show and the SC not responding messages do not show.




Code: Select all
on addRecord tPath,tRowData
put merge ("sqlite3 [[tPath]] `insert into Names values ([[tRowData]]);`") into tCommand
put THTask("launch",tCommand) into tTaskID
repeat while THTask("isRunning",tTaskID) = true
end repeat
end addRecord
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THTask (NEW)

Postby johnjohnston1 » Sun Jun 19, 2011 1:14 am

put THTask("isRunning",tTaskID) into tRunning


Hi Terry,
I was going to ask about that. Great stuff. As is the method of beach ball dodging.

Thanks

John
User avatar
johnjohnston1
 
Posts: 196
Joined: Sun Jul 06, 2008 10:42 am
Location: Glasgow, UK

Re: THTask (NEW)

Postby sctell » Sun Jun 19, 2011 10:51 am

Hi,

I have just posted an update.

Nothing major, just improved some coding and error handling:

This script
Code: Select all
put merge ("cd /Users/Terry/Desktop;curl pathToOnlinefileB > fileB;echo 'boo2'") into tCommand
put THTask("launch",tCommand) into gBoo2


produces the following output:
Code: Select all
5795792=5795792=gBoo2
5795792
Error:
curl: (6) Couldn't resolve host 'pathToOnlinefileB'
 
5795792=5795792=gBoo2
5795792
boo2


See the cd script in the example file to see how the above was formatted.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THTask (NEW)

Postby sctell » Mon Jun 20, 2011 7:14 am

Hi,

Another update with what I think is a better arrangement:

The external now calls 2 cd scripts and 2 global variables are set.

The cd scripts are:

taskOutputData
taskErrorData

The globals are:

gTaskOutputData
gTaskErrorData

I call it error because it is using stdError.

However it seems that curl passes some of its output to stdError.

See the examples.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THTask (NEW)

Postby Dave_Higgins » Mon Jun 20, 2011 7:41 am

You can redirect stderr to stdout by using:

command-name 2>&1
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: THTask (NEW)

Postby sctell » Mon Jun 20, 2011 8:27 am

Hi Dave,

I am doing this external with NSTask which is just being passed the curl command.

I monitor stdOut and stdErr in the external and noted that a standard curl call puts some of it's output to stdErr.

It's nothing I have done in the external, just the way Curl does it.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THTask (NEW)

Postby Dave_Higgins » Thu Jun 23, 2011 10:17 am

Looks like you got a hard wired path in there... Ran the "3 at a time" and got:

/bin/sh: line 0: cd: /Users/Terry/Desktop: No such file or directory

among others.
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: THTask (NEW)

Postby sctell » Thu Jun 23, 2011 10:44 am

Hi Dave,

Just access the script and change it to suit your directory then try again.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THTask (NEW)

Postby johnjohnston1 » Sat Aug 06, 2011 3:16 am

Hi Terry,
Is there any update on this external?
I notice you've removed your externals from the forum but there is one available at:
p://www.theaford.co.uk/supercard-externals.html
Is the one on your site newer than the one I've downloaded from this thread earlier?

I would very much like to use the external as I'm using a command pcastaction that doesn't go to the background as I expected when I put an ampersand after it in the shell function. Works beautifully with THTask.

cheers

John
User avatar
johnjohnston1
 
Posts: 196
Joined: Sun Jul 06, 2008 10:42 am
Location: Glasgow, UK

Re: THTask (NEW)

Postby sctell » Sun Aug 14, 2011 12:00 am

Hi John,

Sorry for not replying sooner but had a short break.

The version on my website is the most up to date version. Please use it as you desire.

I am back in the fold but any updates to externals I will place on my website to save any further confusion.

The externals currently there are the latest versions. I did cull the website because some externals were getting a bit long in the tooth but if anyone needs one updating then please let me know and I will do my best.

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: THTask (NEW)

Postby Dan_Kelleher » Sun Aug 14, 2011 11:52 am

Thanks Terry.
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THTask (NEW)

Postby johnjohnston1 » Mon Aug 15, 2011 9:06 am

Hi Terry,
Thanks, your generosity is very much appreciated.

cheers

John
User avatar
johnjohnston1
 
Posts: 196
Joined: Sun Jul 06, 2008 10:42 am
Location: Glasgow, UK


Return to XCmds, XFcns, and XRtns

Who is online

Users browsing this forum: No registered users and 1 guest

cron