![]() |
Quote:
|
Quote:
|
Looks fine, yellow.
Some changes you could make. If you check to see if the network share doesn't exist - and do that first, you can eliminate the code duplication. Also assigning a pointer to the new Finder window makes it clear which window will change. Users may already have a 'Finder window 1' open. Code:
tell application "Finder" |
In general in programming it is a bad idea to loop while doing nothing unless you are deliberately trying to consume CPU power.
Thus I would prefer to see some sort of 'delay' inside the repeat loop that waits for the disk to mount. Something like this: Code:
repeat until (list disks) contains "GROUP_HOME"It would be better to have it exit the loop after a while - e.g. after a fixed (large) number of iterations. Something like: Code:
set timeWaited to 0 |
Thanks for the continued input, I really appreciate it!
I took (parts) of the your suggestions and put them in the code. I think the removal of the code redundancy will wait until v2 (Cocoa version?), as the script/app is very small, it doesn't really bother me at the moment.. even though it's probably "good form" programatically. I just need to get something workable 'out-the-door' (so to speak) and then I can concentrate on cleaning it up and stuff like asking for/using values like 'username', so I don't have to recreate the wheel for each user. You're quite right about the 'Finder window 1' (I actually took that from recording some actions in the Finder to see what the associated AppleScript would be), so I've implemented your use of the mountFoo variables. And the addition of the delay and associated sane exiting on failure is also a great help and has made it's way into the script. Thanks again! EDIT: I'm experimenting with: set _username_ to "yellow" as string With hopes that this will populate _username_ throught the script. I'm just not sure how it will be handled in the "mount volume" line. RE-EDIT: I used guardian's "&_username_&" suggestion and it worked! |
Quote:
The previous 'on error' statement should catch any mounting issues. Yellow, you can get error codes sent to the 'on error' handler so that you can handle different errors in the same handler. Bet it's in your book. I'd replace the loop with a single delay statement. The second error handler would deal with any problems associated with being unable to get the correct full path to the SMB share. |
Quote:
I find the evolution of the script quite interesting and wonder what the final will look like once I reach the end of the book and you all get tired of helping me. :) |
try using
Code:
tell application "System Events"this gets the OSX user name. Not sure if you are using the same user name on the smb |
Quote:
|
Quote:
Quote:
Code:
repeat until (list disks) contains "GROUP_HOME"Quote:
Quote:
|
Quote:
Does this script take much CPU on your system? Code:
tell application "Finder" |
Quote:
|
Quote:
|
Quote:
Script Editor isn't a good test environment for determining deployment considerations. When I run the above script from Script Editor on my iBook, it also shows CPU usage approaching 100%. But if I save it as a compiled Application, and run that, the CPU usage averages less than 1 %. |
Same here, saved as an app, it maxed out at 1%. Larger RAM usage then with Script Ed, though.. about 50% larger.
|
I don't save everything as a compiled application though.
|
Most of my AppleScripts are inserted as scripts into QuicKeys X3 so I can run them with a hotkey or easily call them from another QK sequence. Run in that way, a delay is not the CPU eater I thought it was; QK uses less than 4% of CPU time, declining to 1 at the point that the delay times out. Perhaps an AS delay is now using the sleep shell function.
|
| All times are GMT -5. The time now is 06:03 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.