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
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Himanshu sharma
Himanshu has marvelous coding skills. In Free time too he loves to do coding and sometimes play Cricket.