Applescript user input

Hi, i can't understand why my script don't work. It works ok if i

manually insert the theRep times and the product theWeight.


set theRep to text returned of (display dialog "How many times do we repeat?" default answer "")

set theWeight to text returned of (display dialog "Product weight?" default answer "")


repeat theRep times


delay 0.2

tell application "System Events"

tell application process "Safari"


click (clickat {1160, 660}) -- Click Weight


delay 0.2


key code 0 using {command down} -- Select all


delay 0.2


keystroketheWeight-- Insert weight


delay 0.2


click (clickat {1060, 810}) -- Click Save changes


delay 0.2


key code 124 using {option down, command down} -- Go to next tab


delay 0.2

end tell

end tell

end repeat

Mac Pro, macOS Sierra (10.12.6)

Posted on Jul 30, 2018 11:51 PM

Reply
Question marked as Top-ranking reply

Posted on Jul 31, 2018 10:22 PM

Hi and thank you, this worked like a charm.


The webpage is our online shops backend page for one product so i could not give that.

But i cannot understand why my script didn't work. I was running the orginal script with

safari being the frontmost application and running the script from the script menu (specific scripts for safari only).

So the only thing i was missing was:


tell application "Safari"  
     activate  
end tell 


Well you live and learn 🙂

Similar questions

3 replies
Question marked as Top-ranking reply

Jul 31, 2018 10:22 PM in response to rccharles

Hi and thank you, this worked like a charm.


The webpage is our online shops backend page for one product so i could not give that.

But i cannot understand why my script didn't work. I was running the orginal script with

safari being the frontmost application and running the script from the script menu (specific scripts for safari only).

So the only thing i was missing was:


tell application "Safari"  
     activate  
end tell 


Well you live and learn 🙂

Jul 31, 2018 11:44 AM in response to rccharles

-- Anyway, you need to bring safari to the front. click & keystroke happens to the frontmost window.


set theRep to text returned of (display dialog "How many times do we repeat?" default answer "")
log "theRep is " & theRep

set theWeight to text returned of (display dialog "Product weight?" default answer "")

log " theWeight is " & theWeight
-- Anyway, you need to bring safari to the front. click & keystroke happens to the frontmost window.
tell application "Safari"
    activate
end tell

repeat theRep times
    log "looping..."
    
    delay 0.2
    
    tell application "System Events"
        
        tell application process "Safari"
            
            click (click at {1160, 660}) -- Click Weight
            
            delay 0.2
            
            key code 0 using {command down} -- Select all
            
            delay 0.2
            
            keystroke theWeight -- Insert weight
            
            delay 0.2
            
            click (click at {1060, 810}) -- Click Save changes
            
            delay 0.2
            
            key code 124 using {option down, command down} -- Go to next tab
            
            delay 0.2
            
        end tell
        
    end tell
    
end repeat

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript user input

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.