airmessage / airmessage-server

AirMessage's native message relay server for Mac
Apache License 2.0
183 stars 12 forks source link

Sync issue in create outgoing facetime? #5

Open larsdennert opened 2 years ago

larsdennert commented 2 years ago

tell application "System Events" tell process "FaceTime" --Click the "New FaceTime" button set createButton to button 2 of window 1 click createButton DO YOU NEED A DELAY OR CHECK FOR EXIST HERE? SEEMS ANYTIME YOU WANT TO CREATE A WINDOW OBJECT YOU ARE NOT GUARANTEED OF THE TIMING IN A THREADED OS IS MY THOUGHT. THE SHEET MAY NOT YET EXIST WHEN YOU TRY TO GET IT. --Get the sheet set createSheet to sheet 1 of window 1

        --Focus the input field
        set inputField to text field 1 of createSheet
        set focused of inputField to true
tagavari commented 2 years ago

Have you run into an issue where the input field is not available when the script tries to access it?

My understanding is that in most cases AppleScript calls will block until the UI interaction goes through, but this may not be the case.

larsdennert commented 2 years ago

That would be nice but you have delay statements all over. Leads me to believe you were dealing with those issues and seems to be the error messages people are getting where resources don't exist when your next call happens. Although the call to click a bottom blocks until the action is complete, it may not block for creation of the next window object that the click creates. Just my thoughts. I should qualify that i have not used apple script.

larsdennert commented 2 years ago

Alpha 8 is more reliable. If you still get reports on this issue, try including the menu click at the top inside the repeat loop. click menu item 1 of menu of linkButton

larsdennert commented 2 years ago

I really think the following statement needs to be inside the repeat loop to copy the ft link:

click menu item 1 of menu of linkButton

Otherwise the repeat loop does nothing but repeatedly check for a clicked link that was missed and will never be clicked again. I'm getting this error on the timeout.

tagavari commented 2 years ago

Thank you for helping to troubleshoot this! I understand where you're coming from with the delay statements, though I can't recreate this issue in this specific case.

I've created this script that opens the menu and immediately copies the link, then displays a dialog message that says whether the menu was present. Can you open it in Script Editor and run it on your machine and let me know if it works?

copylink.applescript

tell application "System Events"
    tell process "FaceTime"
        set linkButton to button 1 of window 1
        click linkButton
        if menu of linkButton is {} then
            display dialog "is empty"
        else
            click menu item 1 of menu of linkButton
            display dialog "is not empty"
        end if
    end tell
end tell
larsdennert commented 2 years ago

Great idea. I'll mess with the script and see what I can do to get some fails for the whole sequence. That requires no functioning coding environment except Applescript. One of my Macs is dead slow so that will be perfect also as the lowest common denominator for people using old macs. If I get some code that looks robust I'll send it back for you to try.

larsdennert commented 2 years ago

Well I think the issue is Facetime gets left in peculiar states, sometimes half way through the automation. Sometimes requests get stacked up and then they all flood in. It seems to be a MacOS/FT issue of some sort. Maybe closing FT after every call will help alleviate the problem. I ran the scripts and messed with variations of it, but they generally work as intended. When AM does it, sometimes a menu gets stuck. Eventually I could no longer receive FT calls on the phone and can only start them. Airmessage was not relaying the notification despite restarting all devices. I'll keep experimenting... I've never gotten FT to work from a browser.