Two Sincere Q's From A newbie

I wrote a compiled apple script that inputs a “123” password into a PDF when it opens. I still have 2 problems I can’t lick. I’d be grateful in advance for any help with my 2 problems. Please know that I’m still new and often don’t comprehend the answers if they’re too complex.

Here’s the script:

tell application “Finder” to close every window
tell application “Finder”
open file 1 of folder “Macintosh HD:Applications:pdfFolder”
end tell
set keyValue to “123”
tell application “System Events” to keystroke keyValue
set keyValue to return
tell application “System Events” to keystroke keyValue

(Recent discovery: Separating “Return” and the 123 password, allowed me to compile).

The two problems:
1)
The script will be on other people’s machines and so, I can’t use “Macintosh HD” - this works on my machine because that the volume’s name. I tried opening the “startup” disk and retrieving the name in the events log but couldn’t do it. Is there a generic name for the start up volume that works across versions of OSX? I couldn’t find one. “Startup Disk” didn’t work.

Sorry if this is overload but my last problem is that I have to close apps prior to launching the pdf (otherwise, there’s at least one hacker I’ know that will simply take a text document and place it where the PW “123” is pasted. I’ve experimented on my own and tried other people’s suggestions. Problem is, the apps are open on other individual machines (which I can’t foresee) and also, if the dialogue box comes up, asking the user which apps to close, that will give hacker a chance to modify it and then use a text document to catch the 123 PW.

Again, I really appreciate any help on this. Thank you.

Model: Mac Book Pro
AppleScript: 2.3
Browser: Firefox 26.0
Operating System: Mac OS X (10.6)

for problem 1:


tell application "Finder"
	set myFolder to path to applications folder & "pdfFolder"
	open file 1 of folder myFolder
end tell

though this assumes they have the folder “pdfFolder” in their Applications folder. So maybe it’s better to ask user to select the file or folder?


tell application "Finder"
	open (choose file)
end tell

OR


tell application "Finder"
	set myFolder to (choose folder)
        open file 1 of folder myFolder
end tell

for problem 2:
this script will quit all apps except those added to the keep list


--"Quit All Apps"
-----------------------------

--PROPERTIES:

property keepList : {"Finder"}

--SCRIPT:

-- get list of open apps
tell application "System Events"
	set visible of every process whose visible is false to true
	set open_apps to name of every application process whose accepts high level events is true and visible is true
end tell


-- quit each app
ignoring application responses
	repeat with this_app in open_apps
		if this_app is not in keepList then quit application this_app
	end repeat
end ignoring



--END

adapt as required :slight_smile:

Problem 1:

Change “Macintosh HD:Applications:pdfFolder” into

(posix file "/Applications/pdfFolder" as text)

We’re using a posix path so we don’t need to know the volume name. In UFS (Posix file paths) every (absolute) file path starts from the root directory of the boot volume instead of device names.

Another option for getting the name of the startup disk (Problem 1):

set startupDiskName to item 1 of (list disks)

or the Mac path of the startup disk:

set startupDiskPath to item 1 of (list disks) & ":"

or the path of your pdfFolder:

set myPath to item 1 of (list disks) & ":Applications:pdfFolder"

@Flex20: list disk is not only deprecated but there is also no guarantee that item 1 will always be the boot volume.

It still works but, I agree it’s not safe to use in the long run. Your “posix file …” or dewshi’s “set myFolder to path to applications folder & …” are better solutions.

more reliable ways

set startupDiskName to boot volume of (system info)

or

tell application "System Events" to set startupDiskName to name of startup disk

First problem, a generic name for Macintosh HD was solved by Dj Bazzie Wazzie’s solution,
posix file “/Applications/pdfFolder” as text

I have barely an idea of why it works (not a very good scriptor is I) …but Thank you so much.

I came close to solving the other problem but I think I probably either didn’t understand your proposed solutions or wasn’t able to communicate what I was doing. Sorry.

My script is a pdf password inputter. It goes straight to a folder inside Applications (inside primary drive) and opens a folder “pdf folder” (to be placed by an installer) and opens the first pdf in the list. So, if you had a pdf file, called “AAAA” and it had an open password of 123, the script would open it. Reason that I need to quit all apps immediately prior to execution is that hackers quickly slip a text doc, apple script or pdf and “catch” the password before it gets into the open password field.

I tried your solutions re: quitting apps. I was able to get Dewshi’s script - to almost work (man, it’s powerful) but couldn’t figure out the “keep list.” It immediately closed everything but I didn’t know the proper syntax or something for the keep list. I put

property keepList : {“Finder” and “AppleScript Editor” and “Firefox”}
also tried {“Finder” & “AppleScript Editor” & “Firefox”}

What am I doing wrong?

a list is comma separated

property keepList : {"Finder", "AppleScript Editor", "Firefox"}

AppleScript Language Guide: AppleScript Lexical Conventions

A commma - I did figure that out (duh). Thank you, Stefan.

Not to beat this to a dead horse but my script has a problem that may be too much for (that is, too much to ask from) this forum. I’m working on it but it seems out of my reach - at least for many moons.

To give it a shot: if the script doesn’t recognize an app in the keeplist or an open app., a dialogue box, actually a navigation dialogue box opens, “Choose an Application.” Left hand at the top it says, “Where is Arm” …Where is ARM? I checked the Activity monitor plus, plus and I never heard of and can’t find “ARM.” Other times, “Where is Filemaker” (if it’s open), and almost every time, no matter how many times I make Reader my default pdf opener, and do it in every which way, “Where is Acrobat Pro”, on and on and on.

The good news (sorta) is that if I select Cancel, the navigation box closes but it returns with another similar question about another app and when it’s finally done, the apple script executes. Rather than instructing eventual users to either choose an app or cancel, , I’m trying to create an If-then script which just cancels the darn navigation box so the script can finish and I’ll live with open apps. Instructing users to choose an app won’t work and it also leaves open the possibility that a hacker can intentionally choose a different app, thereby leaving one that can be used to splatter the 123 password. Thank you in advance. I understand if this is too much to ask for, in this forum. If it is, forgive me.

Model: Mac Book Pro
AppleScript: 2.3
Browser: Firefox 26.0
Operating System: Mac OS X (10.6)

Addendum to above: one interesting part of the navigation box issue is that the script learns. I keep hitting cancel and then, I can use the script over and again, and the navigation box never returns. I’m near-certain but of course don’t know, this must be machine specific. Otherwise, I would just hit cancel, over and again, with regard to every app - before sending it out. Wishful thinking. I have to develop the script, if the “Choose an Application” dialogue box opens, continue to select cancel until it stops" would be the goal. Thanks…