Writing applescript to get active window tab detail

Posted By : Himanshu sharma | 27-May-2016

  

This is the code to get active window data in node by applescript . This gives details of appname,broweser detail, url of it and title .

global currentTabTitle,currentTabUrl,frontAppName,appid

                                 set currentTabTitle to ""

                                 set currentTabUrl to ""

                                

                                 tell application "System Events"

                                 set frontApp to first application process whose frontmost is true

                                 set frontAppName to name of frontApp

                                 set x to first process whose its frontmost is true

                                 set appid to unix id of x

                                 tell process frontAppName

                                 tell (1st window whose value of attribute "AXMain" is true)

                                 set windowTitle to value of attribute "AXTitle"

                                 end tell

                                 end tell

                                 end tell

                                 tell application "System Events" to set frontApp to name of first process whose frontmost is true

                                 if (frontApp = "Safari") or (frontApp = "Webkit") then

                                 using terms from application "Safari"

                                 tell application frontApp to set currentTabUrl to URL of front document

                                 tell application frontApp to set currentTabTitle to name of front document

                                 end using terms from

                                 else if (frontApp = "Google Chrome") or (frontApp = "Google Chrome Canary") or (frontApp = "Chromium") then

                                 using terms from application "Google Chrome"

                                 tell application frontApp to set currentTabUrl to URL of active tab of front window

                                 tell application frontApp to set currentTabTitle to title of active tab of front window

                                 end using terms from

                                 end if

                                 

                                 

                                 

                                 return {currentTabTitle,currentTabUrl,frontAppName,appid}

 

THANKS

About Author

Author Image
Himanshu sharma

Himanshu has marvelous coding skills. In Free time too he loves to do coding and sometimes play Cricket.

Request for Proposal

Name is required

Comment is required

Sending message..