Wanting to run some Javascript from within AppleScript

Joined
Feb 22, 2025
Messages
1
Reaction score
0
This could see me lots of time if I can get it to work. My current manual effort is to copy an item from an excel spreadsheet, switch to Safari, press a button to (Create your own) which unhides a textbook, I then paste the excel item into the textbook and press the Add button - then go back to Excel to get next item over and over again.

I have some AppleScript code that captures items from an excel spread sheet and each item is passed to the Javascript code to hopefully do the click button and paste functions.

Since it is my own computer, I ty to control the environment by having just excel and just the workbook for may entries open and just one Safari tab open with the page having my buttons and input field on it.

SO far the Excel part seems to be working fine but when I tell Safari o do the Javascript it is not working.

Thank you


The current code is
Code:
on run
    
    tell application "Microsoft Excel"
        activate
        set itemcount to value of cell "A1"
        display dialog itemcount
        
        repeat with i from 2 to itemcount + 1
            activate "Microsoft Excel"
            
            set newcell to "A" & i
            set output to value of cell newcell
            display dialog output
            
            tell application "Safari" to tell document 1 to do JavaScript
            "document.getElementsById('msku-custom-option-link').click();"
            "document.getElementsById('msku-custom-option-input').value=output"
            "document.getElementsById('msku-custom-option-add').click();"
        end repeat
        
    end tell
    
    -- button1 msku-custom-option-link
    -- text msku-custom-option-input
    -- button2 msku-custom-option-add
    
end run
 

Attachments

  • Screen Shot 2025-02-22 at 1.03.10 PM.png
    Screen Shot 2025-02-22 at 1.03.10 PM.png
    24.2 KB · Views: 3
  • Screen Shot 2025-02-22 at 1.03.24 PM.png
    Screen Shot 2025-02-22 at 1.03.24 PM.png
    22.1 KB · Views: 3

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,261
Messages
2,571,308
Members
47,976
Latest member
AlanaKeech

Latest Threads

Top