I have a piece of applescript (added underneath) that basically does two things
- grab the selected text and takes that to url request (e.g. urban dictionary url) in order to have a safari window popup with the result (translation or definition)
- push some usage statistics to google analytics using curl.
Adding the google analytics curl push part ('nr 2') makes the first part (as experienced by end-user) significantly slower. My assumption here is that somehow this google analytics part (curl push) is done prior to the url request (instead of after or simultaneously). How can I can speed up the visible part (i.e. the url request), like by making this simultaneous with the url push making sure the url request comes first?
on run {input, parameters}
set output to "https://www.urbandictionary.com/define.php?term=" & urldecode(input as string)
set Cntr_post to "https://www.google-analytics.com/collect?v=" & 1 & "&t=" & event & "&tid=" & "UA-99571xxx-1" & "&cid=" & 12345678 & "&ec=" & "EasyLookUp" & "&ea=" & "UrbanDictionary" & "&el=" & "xxx_test_cp" & "&aip=" & 1
do shell script "curl " & quoted form of Cntr_post
return output
enter code here
end run
on urldecode(x)
set cmd to "'require \"cgi\"; puts CGI.escape(STDIN.read.chomp)'"
do shell script "echo " & quoted form of x & " | ruby -e " & cmd
end urldecode
It works as coded above. But commenting out the google analytics part makes just the first action (the url request with the safari popup) significantly faster (avg of 3.5 seconds instead instead of 5.5sec).
Can I change this code in such a way that the analytics part (curl push) does not delay the first part?
Update 1: here is all an image where it is all in one canvas

Update 2: if I split the code up, to make the analytics part run afterwards this works, but it does not run 'in the background' it waits until the first is finished (this means it waits until the safari popup is closed).. But for now this seems the best option.
Thank you user3439894 and Ted Wrigly for your help!
@Ted Wrigly: I will try your answer next, thank you!
enter code herepart, or there is another action after the Run AppleScript action. It would probably be more helpful if you showed a screenshot of the Automator Service/Quick Action or at least provide the missing details. That said, is the some reason why you can not separate the tasks so that everything necessary for the User happens first, then in the background the Google Analytics part runs?do shell scriptcommand is pausing the script while it waits for the command to signal that it has completed. if you detach that unix command as a separate process, the script will continue immediately.