Scripters,
I’ve been learning applescript for just the past week, but my head spins when thinking about using lists and delimiters.
My app’s purpose is to streamline opening about 5-30 safari tabs. It will ask which employees to use (less than 40 maximum will ever be in this list) It will then auto run safari, fill in yesterday and todays date, go through the chosen employees in step 1, auto fill their respective work location and employee name from two separate dropdowns, open a new safari tab, and repeat this through the chosen list. ̶(̶a̶n̶o̶t̶h̶e̶r̶ ̶r̶o̶a̶d̶b̶l̶o̶c̶k̶ ̶w̶a̶s̶ ̶f̶i̶n̶d̶i̶n̶g̶ ̶t̶h̶e̶ ̶m̶o̶s̶t̶ ̶e̶f̶f̶i̶c̶i̶e̶n̶t̶ ̶w̶a̶y̶ ̶t̶o̶ ̶r̶e̶p̶e̶a̶t̶ ̶o̶p̶e̶n̶i̶n̶g̶ ̶t̶h̶e̶ ̶c̶h̶o̶s̶e̶n̶ ̶l̶i̶s̶t̶ ̶i̶n̶ ̶n̶e̶w̶ ̶t̶a̶b̶s̶,̶ ̶y̶o̶u̶'̶l̶l̶ ̶s̶e̶e̶ ̶w̶h̶a̶t̶ ̶I̶ ̶m̶e̶a̶n̶ ̶i̶n̶ ̶t̶h̶e̶ ̶s̶c̶r̶i̶p̶t)̶*edit: I think I cleaned up the script so that it repeats without the redundant code. however it opens an extra tab that isn’t autofilled, I just set it to close the last tab as a workaround to this issue in the meantime. New code pasted below
̶
So far, the app will ask who to pull up data for, open safari, and autofill the date range, then repeat this the same number as number of employees chosen. But I’m stuck on how to use a delimiter to repeat my script through only the chosen employees, and be able to attribute which employees reside at which location and have which badgenumber.
The employees work at one of just 3 locations. They all have a unique ElementById that I’ll have to pull from the website source code, I call it their BadgeNumber.
I feel like if I just knew how to do this for 2 or 3 employees I could figure out how to scale it up. Any advice or tips would be greatly appreciated!
My script so far reads:
set userName to long user name of (system info)
set employee to (choose from list {"Emp1", "Emp2", "Emp3", "Emp4", "Emp5", "Emp6", "Emp7", "Emp8", "Emp9", "Emp10"} with title "Commitment Keeper - By: Foobar." with prompt "Welcome, " & userName & " " & return & "Choose Your Managers Below:" with multiple selections allowed)
count employee
(*** How to use delimiter to assign employees their location and badgenumber?
set Location to {"Loc1", "Loc1", "Loc1", "Loc1", "Loc1", "Loc2", "Loc2", "Loc2", "Loc3", "Loc3"}
set BadgeNumber to {"badge1", "badge2", "badge3", "badge4", "badge5", "badge6", "badge7", "badge8", "badge9", "badge10"}
***)
set {month:today_month, day:today_day, year:today_year} to (current date)
set {month:yesterday_month, day:yesterday_day, year:yesterday_year} to (current date) - 1 * days
set thePrefix to ""
set theNumber to ""
set theIcon to note
activate
tell application "Safari"
activate
make new document with properties {URL:"https://myfoobar.com/portal/authsec/dashboard/Management/General"}
delay 0.5
-- wait for webpage to finish loading
repeat
if (do JavaScript "document.readyState" in document 1) is "complete" then exit repeat
delay 0.5
end repeat
delay 0.5
-- repeat n times
repeat (number of employee) times
-- expand search area
tell document 1
delay 0.5
(*** will unblock this when on VPN to test if it waits for page to load properly before proceeding.
repeat
if (do JavaScript "document.readyState" in document 1) is "complete" then exit repeat
delay 0.5
end repeat
***)
do JavaScript "document.getElementById('callBackbtnlocale').click();"
delay 1.5
tell application "Safari"
-- autofill yesterdays date
do JavaScript "document.getElementById('cb_srch_pf_fmonth').value = '" & yesterday_month * 1 & "'" in document 1
do JavaScript "document.getElementById('cb_srch_pf_fmonth'). onchange()" in document 1
do JavaScript "document.getElementById('cb_srch_pf_fday').value = '" & yesterday_day & "'" in document 1
do JavaScript "document.getElementById('cb_srch_pf_fyear').value = '" & yesterday_year & "'" in document 1
--autofill todays date
do JavaScript "document.getElementById('cb_srch_pf_tmonth').value = '" & today_month * 1 & "'" in document 1
do JavaScript "document.getElementById('cb_srch_pf_tmonth'). onchange()" in document 1
do JavaScript "document.getElementById('cb_srch_pf_tday').value = '" & today_day & "'" in document 1
do JavaScript "document.getElementById('cb_srch_pf_tyear').value = '" & today_year & "'" in document 1
(*** how to use delimiter and employee together for location and badge number?
-- autofill employee location
do JavaScript "document.getElementById('cb_site').value = 'Location'" in document 1
-- autofill employee name
do JavaScript "document.getElementById('cb_manager').value = 'BadgeNumber'" in document 1
***)
end tell
end tell
tell window 1
-- I expect 1 extra tab to be opened and not autofilled since this is the last step of the repeat, how to address? just delete the last tab?
set current tab to (make new tab with properties {URL:"https://myfoobar.com/portal/authsec/dashboard/Management/General"})
end tell
end repeat
end tell
-- close last tab since I dont know how to get the repeat to not open it
tell window 1 of application "Safari" to close tab -1
tell window 1 of application "Safari" to set current tab to tab 1
activate
display notification "Opened " & number of employee & " Tabs" with title "Thanks For Using Commitment Keeper! v1.0" sound name "Glass.aiff"