angularapplescriptapplescript-objcapplescript-numbersapplescript-studio

Calling a angular frontend from applescript to select an item from a list


I have an angular server running in the localhost, and I want to call it from Applescript. The scenario is I have a list of tweet IDs inserted as a list in angular, and it's running as localhost. Now, I have the same tweet link open in another browser now I want to read the tweet link, fetch the tweet ID and call the angular server to select the respective tweet ID and click on submit button. Tweet IDs are always predefined.

I can read the tweet link and fetch the tweet ID but cannot call the angular server. Can you please suggest it?

code to read and fetch tweet id

display dialog "Name of the browser?" default answer "Safari"
set inp to text returned of result

global link1 -- declare y
set link1 to "" -- initialize y

tell application "System Events"
    if inp is "Google Chrome" then
        tell application "Google Chrome" to return URL of active tab of front window
    else if inp is "Safari" then
        tell the application "Safari" to set link to URL of front document
        set teststring to "https://twitter.com/Jimmy_Wine/status/1090281915238834176"
        set tweets to words of teststring -- convert string to list of words
        set tweetid to the last item of tweets
        return tweetid
    else
        return
    end if
end tell

Angular GUI

enter image description here


Solution

  • Use automater and do following

    Applescript

    tell application "Safari"
        tell window 1
            tell current tab
                set URL to "http://localhost:4200/"
                delay 1
            end tell
        end tell
    end tell
    

    call Jaavscript and do following

    function run(input, parameters) {
        
    var safari = Application("Safari");
    safari.includeStandardAdditions = true;
        
    var safari = Application("Safari");
    safari.includeStandardAdditions = true;
    var jsScript = "";
    jsScript += "document.getElementById('your id name').click();"; 
    jsScript += "document.getElementsByClassName('your class name')[0].click();";
    jsScript += "document.getElementsByClassName('your class name')[0].click();";
    safari.doJavaScript(jsScript, { in: safari.windows[0].currentTab });
    
    return input;
    }
    

    It will click a particular tweetid and submit button to call the server, you can change the class name by id if you are using id for search field.