 |
 |
Applescript Help
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2000
Location: Boston
Status:
Offline
|
|
Just getting my feet wet with Applescript which is pretty amazing.
This is what I'd like to do.
I have one file on an encrypted disk. I'd like text edit to launch that file automatically when I mount the disk image.
Any ideas?
|
|
-Toyin
13" MBA 1.8ghz i7
"It's all about the rims that ya got, and the rims that ya coulda had"
S.T. 1995
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
You may need to do it the other way around. Ie, write a script that mounts the disk image and then opens the file in TextEdit.
Otherwise, you'd need something that was constantly watching to see when the disk image was being mounted. It would need to be running all the time, and either polling (bad!) or waiting for a notification (which I don't know if they exist for disk mounting).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2000
Location: Columbus, OH
Status:
Offline
|
|
Originally posted by Toyin:
Just getting my feet wet with Applescript which is pretty amazing.
This is what I'd like to do.
I have one file on an encrypted disk. I'd like text edit to launch that file automatically when I mount the disk image.
Any ideas?
This should do the trick. Using Script Editor, save it as an applicaton and check the "Run Only" and "Stay Open" options. This script will check every second to see if the disk is mounted. Then it will open your file and quit. Even though the idle loop is done every second, the CPU usage is very low. You will have to add your own error handling. Enjoy!
Code:
on idle
tell application "Finder"
if disk "test" exists then
tell application "TextEdit"
activate
open file "test:test.txt"
quit me
end tell
end if
end tell
return 1
end idle
|
|
HyperNova Software, LLC
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
You could add an AppleScript Folder action to the DMG root dir - except that would open the File every time you opened the folder - so if you mounted the disc it would work, but if you closed the window and opened it again the script would also run again.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2000
Location: Boston
Status:
Offline
|
|
Originally posted by msuper69:
This should do the trick. Using Script Editor, save it as an applicaton and check the "Run Only" and "Stay Open" options. This script will check every second to see if the disk is mounted. Then it will open your file and quit. Even though the idle loop is done every second, the CPU usage is very low. You will have to add your own error handling. Enjoy!
Code:
on idle
tell application "Finder"
if disk "test" exists then
tell application "TextEdit"
activate
open file "test:test.txt"
quit me
end tell
end if
end tell
return 1
end idle
Thanks a lot. That really got me on the right path. This is what I ended up doing.
Code:
on idle
tell application "Finder"
if disk "Secure" exists then
tell application "Finder"
open "Secure:any document"
quit me
end tell
end if
end tell
return 1
end idle
tell application "DiskImageMounter"
activate
open file "MacintoshHD:Users:username:Documents:Secure.dmg"
end tell
This works great!!! Now I can place all my "secure" documents on one disk image and create scripts to launch specific files as I add them (iInstead of creating different images for each file). It works nicely too. Launch the script, password dialog box comes up, enter password and then the document is automatically launched. The script quits immediately after so there's no CPU use either.
Thanks again
|
|
-Toyin
13" MBA 1.8ghz i7
"It's all about the rims that ya got, and the rims that ya coulda had"
S.T. 1995
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2003
Location: Amsterdam, NL
Status:
Offline
|
|
Can't you simply put a folder action on the /Volumes directory? Everytime a disk image is mounted, it appears there. The Applescript would then simply confirm that the .dmg in question has been mounted and run the rest of the sript.
Originally posted by Brass:
You may need to do it the other way around. Ie, write a script that mounts the disk image and then opens the file in TextEdit.
Otherwise, you'd need something that was constantly watching to see when the disk image was being mounted. It would need to be running all the time, and either polling (bad!) or waiting for a notification (which I don't know if they exist for disk mounting).
Cheers,
mbotta
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2000
Location: Columbus, OH
Status:
Offline
|
|
Originally posted by mbotta:
Can't you simply put a folder action on the /Volumes directory? Everytime a disk image is mounted, it appears there. The Applescript would then simply confirm that the .dmg in question has been mounted and run the rest of the sript.
Cheers,
mbotta
I like your idea but how do you attach a Folder Action to a hidden directory?
|
|
HyperNova Software, LLC
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2000
Location: Columbus, OH
Status:
Offline
|
|
Originally posted by Toyin:
Thanks a lot. That really got me on the right path. This is what I ended up doing.
Code:
on idle
tell application "Finder"
if disk "Secure" exists then
tell application "Finder"
open "Secure:any document"
quit me
end tell
end if
end tell
return 1
end idle
tell application "DiskImageMounter"
activate
open file "MacintoshHD:Users:username:Documents:Secure.dmg"
end tell
...
Thanks again
The last part of your script is redundant. It should work the same w/o it.
|
|
HyperNova Software, LLC
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
Originally posted by msuper69:
I like your idea but how do you attach a Folder Action to a hidden directory?
Right-click the desktop and choose "Configure Folder Actions".
Press the Plus button on the left.
Press command-shift-g
type /Volumes
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2000
Location: Boston
Status:
Offline
|
|
Originally posted by msuper69:
The last part of your script is redundant. It should work the same w/o it.
Thanks I'm trying to clean it up.
Code:
on idle
tell application "Finder"
if disk "Secure" exists then
tell application "Finder"
open file "Secure:example.doc"
quit me
end tell
end if
end tell
return 1
end idle
tell application "Finder"
open file "MacintoshHD:Users:username:Documents:Secure.dmg"
end tell
Now the only problem I have is that if the disk Secure is mounted and I run the script, it will launch the file, but will also bring up the password dialog, as if it's trying to mount the disk again. Shouldn't the quit me statement prevent that from happening?
As for the folder actions, that was the 1st way I went about it, but this way is much better. Now I have all my private documents in this one encrypted disk image and use separate applescripts to launch each file.
|
|
-Toyin
13" MBA 1.8ghz i7
"It's all about the rims that ya got, and the rims that ya coulda had"
S.T. 1995
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Actually... wouldn't it be even easier to make the disk image have an auto-open feature, like a lot of CDs do?
Do a google search for the open-source "openUp" utility which you can download and run against your disk image.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2002
Location: New York, NY
Status:
Offline
|
|
Another thing you can do if you don't mind people seeing what files are within the image is to add the files to the Dock or create aliases of them outside the image. When you click on them, the OS will automatically mount the image if it isn't already mounted.
|
|
Vandelay Industries
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2000
Location: Cupertino, CA USA
Status:
Offline
|
|
Here's an example Folder Action script for attaching to the Volumes folder to check to see if a particular drive is mounted. Save the Folder Action script to the Library > Scripts > Folder Actions Scripts folder and use the Folder Actions setup app to attach to the Volumes folder.
Code:
property volume_name : "Firebox"
property file_name : "FOO"
on adding folder items to this_folder after receiving these_items
tell application "Finder"
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
if the kind of this_item is "Volume" and ¬
the name of this_item is the volume_name then
if (exists document file file_name of this_item) then
open file file_name of this_item
end if
end if
end repeat
end tell
end adding folder items to
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Is the disk image read-only, or is it writable? If writeable, then no script is required.
Download the code available at this site and compile it. This is specifically for opening a directory, but a similar method should work for opening a file.
Same concept as an auto-run CD. And this action really should be part of the image/disk itself.
Anyone know how to modify this to work for opening a file rather than a directory?
(currently, if you run it for a file rather than a directory, it will open the parent directory and select the file, but not open it).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2000
Location: Boston
Status:
Offline
|
|
Thanks for all the input. The script that I posted above seems to work well. With 2 clicks or 3 keystrokes (using Launchbar) the image is mounted and the specific files are launched. The drive is read/write and I'll take a look at the script you mentioned Brass, but I like the behavior to be file related, not folder/volume related. The benefit of this behavior is that I can now put several files in the same encrypted disk image.
Anywho, any suggestions for beginner Applescripting? The Help viewer hasn't been too helpful.
|
|
-Toyin
13" MBA 1.8ghz i7
"It's all about the rims that ya got, and the rims that ya coulda had"
S.T. 1995
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|