Wednesday, March 21, 2018

#1 2018-03-13 01:14:39 pm

Registered: 2011-03-17
Posts: 38

Pause & First Run: Would someone give me a hand?

I’ve been working on a script (for years) that launches a pdf and inputs its open password. The purpose of the script is to hide the process of inputting the PW. I finished the script a few months ago - except I've got one problem left that I can't seem to lick. If anyone can give me a hand with this last problem, I’d be grateful.

The first time the script runs (and only the first time) – after a restart, log out or  initial boot - the pauses are a mess. Seems like they’re either lengthened (at the beginning of the script) or shortened (at the end). This mostly happens on Yosemite but on the other OS’s as well. When the pauses don't work, the script fails to achieve its purpose (see below).

Aside from this one problem, the script works consistently  on 10.9, 10.10, 10.11 & 10.12.

One fix that helped (but not completely): I divided the script into 3 parts, a primary and two helper scripts.   The following are the two helper scripts. They finish it.

The first helper script (comes after the main script):


--display dialog one moment giving up after 5--
tell application "Finder"
end tell

delay 0.5

tell application "Finder" to display dialog "One moment..." giving up after 5 buttons {"Cancel"} default button ¬

delay 0.1

--open helper_2--
tell application "Finder"
   open file "helper_2" of folder "MySoftware" of folder "Applications" of startup disk ¬
end tell

The second helper script finishes it:


set keyvalue to “abc” & return
set AppName to POSIX file "/Applications/Adobe"

--open file--
tell application "Finder"
   open file “MyPDF” of folder "MySoftware" of folder "Applications" of startup disk ¬
       using AppName
end tell

delay 0.1

--launch dashboard--
ignoring application responses
   tell application "System Events"
       tell application "Finder"
           tell application "Dashboard"
           end tell
       end tell
   end tell
end ignoring

delay 0.01

tell application "System Events" to keystroke keyvalue

I added the first helper so the script can catch up with itself (during the first run). (I think it does this but I’m not really sure). The 2nd helper  inputs the PW while shifting to dashboard. The purpose of this part of the script: It uses the shift to dashboard to hide  the process of inputting the PW from the user - which is the main purpose of the script.

When the script is run after a restart, the last part of the script moves into dashboard too rapidly and then hangs there. Whereas every time thereafter, the script moves into dashboard and then out, back to the desktop where the pdf appears, with the PW already inputted (and the PW input is concealed.)

The reason my first run problem is a headache: It's the only time the script fails to hide the process of inputting the PW.

I recently noticed, if I wait a long time after the computer boots up (15, 20 minutes), my first run problem doesn’t occur. So, my first question:

Is there a way for a script to monitor how long it has been since the computer booted  or to determine, has the computer completely booted.  If this is possible, an if/then statement be used: If the computer hasn’t completely booted, then present the dialog box, “Please wait until your computer is booted before launching…” else proceed with script.

This would fix my problem.

Last question: The visual effect of shifting into dashboard is the same ‘sliding door’ effect you see when iTunes is enabled. But on the first run, the 'sliding door' moves too rapidly. Whereas on iTunes, the ’sliding door’ moves slowly – more slowly than it ever does for my script when moving into dashboard. Q: Is there a way to control this movement using AS?

I’m still an applescript dabbler but  know more than I did some years back when I first started - and most of my learning has come from reading the posts on the forum…thank you for that…’preciate it…



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)