Tuesday, January 21, 2020

#1 2020-01-04 09:36:06 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 12

osascript with variable and display notification

Great New Year 2020 to all.

1. URL name from a website.
2. Setup a custom command to execute in terminal, this is for debugging but also get status. 
3. When the custom command is stop it will execute osascript for display notification status.

This script only include 1, 3 of above

It took me a hole day to figure out how I could send variable to a string with display notification
and when I use osascript. It was not clear to me as it would be if I only use applescript version instead of osascript.

So my question is...

Would it be possible to do 'do script' with terminal in a better way or more clean instead of mine ??.

Input URL:
-- https://www.tv4play.se/program/ture-sve … t/12499827

-- Script beging
property current_application : application "Safari" -- only for testing

tell current_application
    set thisURL to document of front window
    set theName to name of thisURL as text
end tell

tell application "Terminal"
    if not (exists window 1) then reopen
    set theScrBegin to "osascript -e "
    set theNotifiction to "display notification"
    set theTitle to "with title \"MediaContent from Streams\""
    set theTime to time string of (current date)
    do script theScrBegin & "'" & theNotifiction & " " & "\"" & theName & " " & theTime & " " & "\"" & theTitle & "'" in window 1
end tell

-- Output in terminal
osascript -e 'display notification "Ture Sventon och Bermudatriangelns hemlighet del 3, säsong 1 16:14:53 "with title "MediaContent from Streams"'

Regards, Fredrik

Offline

 

#2 2020-01-04 11:59:53 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 876

Re: osascript with variable and display notification

I'm not sure the following is what you are asking for. Plain AppleScript version, without using the osascript and Terminal:

Applescript:


property current_application : application "Safari"

-- 1) URL info
tell current_application
   activate
   set thisURL to document of front window
   set theName to name of thisURL as text
end tell

-- 2) Custom shell command
-- do shell script ....

-- 3) Shell command is terminated. Display notification.
set theTitle to "with title \"MediaContent from Streams\""
set theTime to time string of (current date)
tell me to display notification theName & " " & theTime & " " & "\"" & theTitle & "'"

delay 5 -- only to see the result longer

Last edited by KniazidisR (2020-01-04 12:21:22 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4, Ram 4 GB
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#3 2020-01-04 09:18:59 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 12

Re: osascript with variable and display notification

Thanks for your input...

The python command I use give me progress bar status, logging so that's why I use it.

Not sure what will happen if I try to run second applescript before the first one has finish.

I should properly use 'word' space and quote instead, and build handler and error code.. smile)

Here is my latest code:
 
on run
    -- Get the URL of current document front window
    tell application "Safari"
        set thisURL to document of front window
        set theURL to URL of thisURL
        set theName to name of thisURL
        set theName to theName & " "
    end tell
   
    -- The command to be executed
    tell application "Terminal"
        if not (exists window 1) then reopen
        set thePy to "python_command" & " "
        -- set thePyParms to ""
        set theScript to " " & "osascript -e" & " "
        set theNotifiction to "display notification " & "\""
        set theTitle to " " & "with title \"MediaContent from Streams\""
        set theTime to time string of (current date) & " " & "\""
        do script thePy & quoted form of theURL & ";" & theScript & "'" & theNotifiction & theName & theTime & theTitle & "'" in window 1
    end tell
end run

Offline

 

#4 2020-01-05 11:33:03 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 876

Re: osascript with variable and display notification

Your python command (with progress bar) can most likely be released in regular AppleScript. Of course, for this  I need to have the python code itself. In order not to guess at the coffee grounds how it works ...

Last edited by KniazidisR (2020-01-05 11:35:15 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4, Ram 4 GB
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#5 2020-01-06 04:59:26 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 12

Re: osascript with variable and display notification

You could get it here...

https://github.com/spaam/svtplay-dl
(You have to live in Sweden to use it...)

Do you happen to know if AppleScript accept job queue, in other words would AppleScript wait
for a new process to be executed if it get a busy statement.

I checked the command from terminal dictionary and their is command: 'busy' that it's boolean
So if 'do script' is running maybe it will first check status of busy are true or false before continue. But I'm not sure if that is what happen.

I did test to run a new AppleScript before the first one has stop, it made a job queue in terminal.
So that's why I like to know if this is normal or specific to the programming language that is used.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)