attaching folder action that runs and then deletes or disables itself

A little history first:
I have a hidden folder that requires admin privileges to open. It contains admin tools and scripts. For quick access I have saved a script bundle to the desktop which will open the hidden folder. Just for fun I have added three icons to it’s Resource folder (applet.icns, openLock.icns & closedLock.icns) so that the bundle’s icon changes; triggered by actions in the script.

You can download the icons for the script here: http://www.mediafire.com/?sharekey=3bb0987b4e883a69d0d290dca69ceb5ce04e75f6e8ebb871
Save the script as an application bundle and then copy the icons to the Resource folder inside of the bundle. Be sure to save it as “Admins Only” or change the appropriate lines of code in the script or it will fail.

For the purpose of this example the script will open your home folder when the correct password is entered. The password is ( enter ).

This script will prompt for the password up to three times if entered incorrectly. Each time the prompt is displayed the prompt and the label for the cancel button changes. If the user fails to enter a correct password on the third attempt it displays an alert that a log of the incident has been created and saves a log file. --For the purpose of this example no log file will be created.

On successful password entry the hidden folder will open and the script bundle icon changes to that of an open lock. As of now the lock changes back to the closed lock icon after a delay of 1.5. What I would like to happen is for the icon to change back only after the folder is closed.

So what I need to do is have the script attach and enable a folder action to the hidden folder that will change the icon once the folder is closed. I have tried including an “on close” folder action script in the Resource folder and have the main script attach and enable it for the hidden folder but this attempt has failed. The second thing I would like for the “on close” script to do is either disable folder actions for the hidden folder and then delete itself from the folders actions or at the least disable folder actions for that folder. The reason for not simply adding the action script to the folder in question manually and then enabling it from the script is that I would like to automate the process for any new folders I have the script open.

Any ideas?



--Admins Only
--Created by DemonXstreeM

-- setting globals
global cnt
global trCnt
global pasKey
global trMsg
global cnMsg
global myPath
global opI
global clI
global cuI
-- end setting globals

-- setting variables
set cnt to 0
set trCnt to 1
set trMsg to {"First Attempt", "Second Attempt", "Final Attempt"}  -- setting prompt list
set cnMsg to {"Cancel", "Never Mind", "I Give Up"} -- setting cancel button list
tell application "Finder" to get folder of (path to me) as Unicode text  -- setting working directory and path to resources
set workingDir to POSIX path of result
set myPath to (workingDir & "Admins Only.app/Contents/Resources/") as string -- end setting working dir and path
set opI to (myPath & "openLock.icns") as string  -- setting icon paths
set clI to (myPath & "closedLock.icns") as string
set cuI to (myPath & "applet.icns") as string  -- end setting icon paths
-- end setting variables

on chk() -- defining the function
	if (cnt < 3) then  -- execute if attempts less then 3
               -- prompt user for password
		set pasKey to display dialog "Enter passkey   " & item trCnt of trMsg default answer "******" buttons {item trCnt of cnMsg, "Ok"} default button "Ok" cancel button item trCnt of cnMsg with title "Open the Vault" with hidden answer
               -- step counters
		set cnt to cnt + 1
		set trCnt to trCnt + 1
		if (the text returned of pasKey is "enter") and (cnt ≤ 3) then  -- execute if less or equal to 3 and correct password
			do shell script ("cp " & "'" & opI & "'" & " " & "'" & cuI & "'")  --change app icon to openLock
			tell application "Finder" to update items of desktop  --refresh desktop
			do shell script ("open $HOME")  --open folder
			delay 1.5
			do shell script ("cp " & "'" & clI & "'" & " " & "'" & cuI & "'")  --change icon back to closedLock
			tell application "Finder" to update items of desktop  --refresh desktop
		else if (cnt ≤ 3) then  -- execute if less or equal to 3 and wrong password
			say "Incorrect Password!" using "zarvox"
			chk() --recall function
		end if
	else  -- execute after final attempt to enter password fails
		say "Congratulations!, You Fail!" using "zarvox"
		display alert "Have a good day" message "Your actions have been logged" as warning giving up after 10
	end if
end chk  -- end defining function

chk() -- calling the function


After thoughts…

This example demonstrates how your script can accept a password before it will open any file(s), folder(s) or even another app all of which may be hidden.

It also demonstrates how to set maximum attempts. In this case it simply displays a message letting the user know that a log file has been created and then cancels the dialog on failure or opens the users home directory on successful entry of the password. No log entry has been created for this example but you should be able to see where it could be handled.

This could be taken a step further by having this app check with another app to see if it can open the dialog in the first place.

e.g. After three failures to enter the correct password it would reset a timer in the launch verification script; preventing the dialog from being opened until the timer has run out. Or perhaps the verification script could be set to lockdown mode which can only be released by the administrator using a hidden bash command or the like.

Any way have fun trying out different techniques and putting it to different uses.

Thx, DXS
–exitus acta probat

Hi,

the easiest way is to use an idle handler.
Btw: there are too many useless coercions in these lines


tell application "Finder" to get folder of (path to me) as Unicode text -- setting working directory and path to resources
set workingDir to POSIX path of result
set myPath to (workingDir & "Admins Only.app/Contents/Resources/") as string -- end setting working dir and path
set opI to (myPath & "openLock.icns") as string -- setting icon paths
set clI to (myPath & "closedLock.icns") as string
set cuI to (myPath & "applet.icns") as string -- end setting icon paths

this does the same


set workingDir to POSIX path of (path to me)
set myPath to workingDir & "Contents/Resources/" -- end setting working dir and path
set opI to myPath & "openLock.icns" -- setting icon paths
set clI to myPath & "closedLock.icns"
set cuI to myPath & "applet.icns" -- end setting icon paths

And a shell call to open the home folder is not needed. The Finder can do it.

Here is your script with an idle handler.
When the homefolder will be closed, the icon will be resetted and the script quits


--Admins Only
--Created by DemonXstreeM

-- setting globals
global cnt, trCnt, pasKey, trMsg, cnMsg, myPath, opI, clI, cuI, flag, homeFolderWindow
-- end setting globals

-- setting variables
set cnt to 0
set trCnt to 1
set flag to false
set trMsg to {"First Attempt", "Second Attempt", "Final Attempt"} -- setting prompt list
set cnMsg to {"Cancel", "Never Mind", "I Give Up"} -- setting cancel button list
set workingDir to POSIX path of (path to me)
set myPath to (workingDir & "Contents/Resources/") -- end setting working dir and path
set opI to myPath & "openLock.icns" -- setting icon paths
set clI to myPath & "closedLock.icns"
set cuI to myPath & "applet.icns" -- end setting icon paths
-- end setting variables

on chk() -- defining the function
	if (cnt < 3) then -- execute if attempts less then 3
		-- prompt user for password
		set pasKey to display dialog "Enter passkey   " & item trCnt of trMsg default answer "******" buttons {item trCnt of cnMsg, "Ok"} default button "Ok" cancel button item trCnt of cnMsg with title "Open the Vault" with hidden answer
		-- step counters
		set cnt to cnt + 1
		set trCnt to trCnt + 1
		if (the text returned of pasKey is "enter") and (cnt ≤ 3) then -- execute if less or equal to 3 and correct password
			do shell script ("cp " & quoted form of opI & space & quoted form of cuI) --change app icon to openLock
			tell application "Finder"
				update items of desktop --refresh desktop
				open home --open folder
				set homeFolderWindow to Finder window 1
			end tell
			set flag to true
		else if (cnt ≤ 3) then -- execute if less or equal to 3 and wrong password
			say "Incorrect Password!" using "zarvox"
			chk() --recall function
		end if
	else -- execute after final attempt to enter password fails
		say "Congratulations!, You Fail!" using "zarvox"
		display alert "Have a good day" message "Your actions have been logged" as warning giving up after 10
	end if
end chk -- end defining function

chk() -- calling the function

on idle
	if flag then
		tell application "Finder" to set homeFolderIsOpen to exists homeFolderWindow
		if not homeFolderIsOpen then
			do shell script ("cp " & quoted form of clI & space & quoted form of cuI) --change icon back to closedLock
			tell application "Finder" to update items of desktop --refresh desktop
			set flag to false
			quit
		end if
	end if
	return 2
end idle

This is a good idea. This works great when you save the application as a “stay open” application. Therefore for this to have the desired effect the folder can only be allowed to stay open as long as the application is running. So to accomplish this goal I modified the script by adding an “on quit” handler and moved some stuff into it. Now if the application is quit the folder is closed (i.e. locked).

Another change… now that the application stays open there is a dock icon. The dock icon always remained a locked icon even when the folder was unlocked. As such I added a line which quits and relaunches the dock when the folder is unlocked. This updates the dock icon to an unlocked icon so it displays properly while the application is running.

There’s a couple other minor changes I made too.

One final thought… you should look at post #5 in this thread which shows how you can keep a password in your keychain. This would be a more secure way to handle the password checking in this application.
http://macscripter.net/viewtopic.php?id=25536


--Admins Only
--Created by DemonXstreeM

-- setting globals
global cnt, trCnt, pasKey, trMsg, cnMsg, myPath, opI, clI, cuI, flag, homeFolderWindow
-- end setting globals

-- setting variables
set cnt to 0
set trCnt to 1
set flag to false
set trMsg to {"First Attempt", "Second Attempt", "Final Attempt"} -- setting prompt list
set cnMsg to {"Cancel", "Never Mind", "I Give Up"} -- setting cancel button list
set workingDir to POSIX path of (path to me)
set myPath to (workingDir & "Contents/Resources/") -- end setting working dir and path
set opI to myPath & "openLock.icns" -- setting icon paths
set clI to myPath & "closedLock.icns"
set cuI to myPath & "applet.icns" -- end setting icon paths
-- end setting variables

on chk() -- defining the function
	if (cnt < 3) then -- execute if attempts less then 3
		-- prompt user for password
		tell me
			activate
			set pasKey to display dialog "Enter passkey   " & item trCnt of trMsg default answer "******" buttons {item trCnt of cnMsg, "Ok"} default button "Ok" cancel button item trCnt of cnMsg with title "Open the Vault" with icon POSIX file clI with hidden answer
		end tell
		-- step counters
		set cnt to cnt + 1
		set trCnt to trCnt + 1
		if (text returned of pasKey is "enter") and (cnt ≤ 3) then -- execute if less or equal to 3 and correct password
			do shell script ("cp " & quoted form of opI & space & quoted form of cuI) --change app icon to openLock
			tell application "Finder"
				activate
				update items of desktop --refresh desktop
				open home --open folder
				set homeFolderWindow to Finder window 1
			end tell
			set flag to true
			tell application "Dock" to quit
			say "Congratulations!, You are allowed to enter!" using "zarvox"
		else if (cnt ≤ 3) then -- execute if less or equal to 3 and wrong password
			say "Incorrect Password!" using "zarvox"
			chk() --recall function
		end if
	else -- execute after final attempt to enter password fails
		say "Congratulations!, You Fail!" using "zarvox"
		display alert "Have a good day" message "Your actions have been logged" as warning giving up after 10
	end if
end chk -- end defining function

chk() -- calling the function

on idle
	if flag then
		tell application "Finder" to set homeFolderIsOpen to exists homeFolderWindow
		if not homeFolderIsOpen then quit
	end if
	return 2
end idle

on quit
	tell application "Finder" to set homeFolderIsOpen to exists homeFolderWindow
	if homeFolderIsOpen then
		tell application "Finder" to close homeFolderWindow
	end if
	do shell script ("cp " & quoted form of clI & space & quoted form of cuI) --change icon back to closedLock
	tell application "Finder" to update items of desktop --refresh desktop
	set flag to false
	say "The folder has been locked!" using "zarvox"
	continue quit
end quit

First of all thx to regulus6633 and StefanK for the help.

I am new to writing scripts for apple so I am still learning as I go.
This will save me time and shorten my code.


global cnt, trCnt, pasKey, trMsg, cnMsg, myPath, opI, clI, cuI, flag, homeFolderWindow
set workingDir to POSIX path of (path to me)
set myPath to workingDir & "Contents/Resources/" -- end setting working dir and path
set opI to myPath & "openLock.icns" -- setting icon paths
set clI to myPath & "closedLock.icns"
set cuI to myPath & "applet.icns" -- end setting icon paths

Also I imagine that finder will also be able to open nested hidden folders as well as home.
e.g. /etc/.admins/.adminTools


set myFolder to ("/etc/.admins/.adminTools") as alias
tell application "Finder"
               activate
               update items of desktop --refresh desktop
               open myFolder --open admin tools
               set adminToolsFolderWindow to Finder window 1

Could you please provide me with a link to this post. I was unable to locate it. Thx

I like this idea. I would think this would also allow me to periodically update the keychain with a new password for extra security with no need to edit the script each time.

Final thought:
I would still like to know if this could be handled by a folder action so that once the script opens the folder it can close “freeing up the CPU” passing the task of setting the icon to default to the folder action handler. And how to implement this. (or is this totally unnecessary?)

Thx again to regulus6633 and StefanK for all of your help.
–exitus acta probat

For those wondering what “exitus acta probat” means, it would be colloquially translated as “the end justifies the means”. :slight_smile:

The link in right there below that sentence. But here it is again. Look at the 5th post.
http://macscripter.net/viewtopic.php?id=25536

Now that I have gotten home from work and have had a chance to play around with the script suggestions I find that while they do work as intended they do not meat my needs.

As it is, the script must stay running for the desired changes to take effect once the folder closes. What I am looking for is for the script to open the folder and then quit. Passing the task of changing the icon back to default to another script. The best way I see of doing this is with a folder action.

I was reading this post http://macscripter.net/viewtopic.php?id=24369 which describes attaching a folder action from within a script. This is the method I wish to use. I have had trouble applying it however and need help with it.

Can any one show me how this can be applied to my script.

What I tried was to create a folder action script. Save it to the Resource bundle of the Admins Only script and then at the point in which the script opens the hidden folder attach the folder actions script to the hidden folder. I think my problem may be with the action script I created.

edit—// I added the keychain verification technique to the script and it works grate. Thx for the tip //—edit

Thx, DXS
–exitus acta probat

Okay. So I now have it working exactly as I wonted it to.

I discovered that the folder action script must be copied to /Library/Scripts/Folder Action Scripts for it to run.

Here is the final Admins Only script and the folder action script.

Thx to everyone who helped out.

Admins Only (main script app)


--Admins Only
--Created by DemonXstreeM

global cnt, trCnt, pasKey, trMsg, cnMsg, myPath, opI, clI, cuI, keychainFileName, passwordItemName, myHome, onClose, fas
set cnt to 0
set trCnt to 1
set keychainFileName to "AdminsOnly.keychain"
set passwordItemName to "adminOnly"
set trMsg to {"First Attempt", "Second Attempt", "Final Attempt"}
set cnMsg to {"Cancel", "Never Mind", "I Give Up"}
tell application "Finder" to get folder of (path to me) as Unicode text
set workingDir to POSIX path of result
set myPath to (workingDir & "Admins Only.app/Contents/Resources/") as string
set opI to (myPath & "openLock.icns") as string
set clI to (myPath & "closedLock.icns") as string
set cuI to (myPath & "applet.icns") as string
set myHome to ((path to "cusr") & "Documents:.Admin Tools") as string
set lib to POSIX path of (path to "dlib")
set onClose to (myPath & "closeIcon.scpt") as string
set fas to (lib & "Scripts/Folder Action Scripts/") as string
on chk()
	if (cnt < 3) then
		set pasKey to display dialog "Enter passkey   " & item trCnt of trMsg default answer "******" buttons {item trCnt of cnMsg, "Ok"} default button "Ok" cancel button item trCnt of cnMsg with title "Open the Vault" with icon POSIX file clI with hidden answer
		set cnt to cnt + 1
		set trCnt to trCnt + 1
		if text returned of pasKey is equal to (getPW(keychainFileName, passwordItemName)) and (cnt ≤ 3) then
			do shell script ("cp " & quoted form of opI & space & quoted form of cuI)
			tell application "Finder" to update items of desktop
			tell application "Finder" to open myHome
			do shell script ("cp " & quoted form of onClose & space & quoted form of fas)
			tell application "System Events" to attach action to ¬
				myHome using ("closeIcon.scpt")
			tell application "System Events" to set folder actions enabled to true
			--delay 0.8
			--do shell script ("cp " & quoted form of clI & space & quoted form of cuI)
			--tell application "Finder" to update items of desktop
		else if (cnt ≤ 3) then
			say "Incorrect Password!" using "zarvox"
			chk()
		end if
	else
		say "Congratulations!, You Fail!" using "zarvox"
		display alert "Have a good day" message "Your actions have been logged" as warning giving up after 10
	end if
end chk

on getPW(keychainFileName, passwordItemName)
	set passwd to missing value
	try
		tell application "Keychain Scripting"
			tell keychain keychainFileName
				tell (some generic key whose name is passwordItemName) to set passwd to password
			end tell
		end tell
	on error theError number errorNumber
		tell me
			activate
			display dialog "Error retrieving the password:" & return & return & theError & return & "Error Number: " & (errorNumber as text) buttons {"OK"} default button 1 with icon stop
		end tell
	end try
	return passwd
end getPW

chk()

closeIcon.scpt (Folder Action Script)


--Admins Only
--closeIcon Folder Action Script
--Created by DemonXstreeM


on closing folder window for this_folder
	set myHome to ((path to "cusr") & "Documents:.Admin Tools") as string
	set dk to POSIX path of (path to "desk")
	set adOnly to (dk & "Admins Only.app/Contents/Resources/") as string
	set clI to (adOnly & "closedLock.icns") as string
	set cuI to (adOnly & "applet.icns") as string
	
	do shell script ("cp " & quoted form of clI & space & quoted form of cuI)
	tell application "Finder" to update items of desktop
	
	tell application "System Events" to remove action from ¬
		myHome using action name ("closeIcon.scpt")
	tell application "System Events" to set folder actions enabled to false
end closing folder window for
closing folder window for

The only remaining issue is that closeIcon.scpt returns the path to the current users desktop. This is then used to set the paths to the icons. Since I intend to only run Admins Only from the desktop this should not be an issue. However if I decide to run it from another location, closeIcon.scpt will fail because it will be looking to the desktop for the app instead of it’s actual location.

I tried using the fallowing to get applications path from the action script.


set appPath to POSIX path of (path to application "Admins Only")

This results in the application being launched and fails to return the path to the application. The error I get is (Admins Only got an error: Can’t continue path to.)

Can anyone show me the proper way to find the path of an application and then return it as a POSIX variable. It would be much appreciated.

Thx, DXS
–exitus acta probat

Again, too many useless coercions :wink:


.
set myPath to POSIX path of (path to me) & "Contents/Resources/"
set opI to myPath & "openLock.icns"
set clI to myPath & "closedLock.icns"
set cuI to myPath & "applet.icns"
set myHome to ((path to documents folder as text) & ".Admin Tools")
set fas to POSIX path of (path to Folder Action scripts)
set onClose to myPath & "closeIcon.scpt"
.

Yes thank you. My code is still not very clean. However I was concentrating more on ensuring all elements of it worked as I had intended it to. Rest assured that my final code will be cleaned up.

In the mean time however any suggestions on how to return the path of the main script from within the folder action script would be most appreciated.

Thx, DXS
–exitus acta probat

If your application is registered by launch services and it has an unique bundle identifier,
you can locate it with something like

tell application "Finder" to set iTunesPath to POSIX path of (application file id "com.apple.iTunes" as text)

btw: I looked into your script Hidden File Settings.
Aside from you reinvented the wheel :wink: the syntax of the shell script line is wrong even it might work:
AppleShowAllFiles is a boolean value and should be set with the -bool switch

defaults write com.apple.finder AppleShowAllFiles -bool YES

Cool Thx.

So I need to register Admins Only with System Events? I take it that this can be accomplished through the script when it launches. Perhaps it checks to see if it is already registered and if not registers itself.

Could you please explain how to register my app with System Events.

And again. Thank you very much for all of the assistance you have provided. I am still new to the world of applescripting and appreciate all the help I have been getting.

Thx, DXS
–exitus acta probat

As far as I know, you can’t register applications for launch services explicitly, they will be registered after the first launch.
But maybe you could locate the application with my CLI LSFindApp which also uses launch services.

Admins Only applescript app bundle

Change Log:
    Added feature: Creates and updates log file with access information
    Added feature:  Sets two minute timer after three failed attempts to open Admin Tools.  User must wait for timer to expire before attempting to
                            open Admin Tools again.
    This version will be looking to ( $HOME/Documents/.Admin Tools ) for the folder to open.  You will need to create the folder in the correct path
    or edit the script accordingly. 

Yes, yes’ I know it still contains too many useless coercions. Don’t worry StefanK. I will be sure to clean it up one of these days.

See post # 1 for required bundle icons & details on compiling/saving the app
see post # 8 for the folder action script.
The icons and the folder action script need to be placed inside of the apps Resource folder.

Admins Only



--Admins Only
--Created by DemonXstreeM


--begin declaring global and property variables
global cnt, trCnt, pasKey, trMsg, cnMsg, myPath, opI, clI, cuI, keychainFileName, passwordItemName, myHome, onClose, fas, admTol, usr, thDate, logMsg, lMsgString
property curTime : 0
property ltdTime : 0
--end declaring global and property variables

--begin define variables
set cnt to 0
set trCnt to 1
set curTime to (current date)'s time as integer
set keychainFileName to "AdminsOnly.keychain"
set passwordItemName to "adminOnly"
set trMsg to {"First Attempt", "Second Attempt", "Final Attempt"}
set cnMsg to {"Cancel", "Never Mind", "I Give Up"}
set logMsg to {" attempted to access Admin Tools on ", " successfully accessed Admin Tools on "}
tell application "Finder" to get folder of (path to me) as Unicode text
set workingDir to POSIX path of result
set myPath to (workingDir & "Admins Only.app/Contents/Resources/") as string
set opI to (myPath & "openLock.icns") as string
set clI to (myPath & "closedLock.icns") as string
set cuI to (myPath & "applet.icns") as string
set myHome to ((path to "cusr") & "Documents:.Admin Tools") as string
set admTol to ((path to "cusr") & "Documents:.Admin Tools:AdminTools_Access.rtf") as string
tell application "Finder" to set usr to get name of first item of (path to "usrs")
set thDate to (current date) as string
set lib to POSIX path of (path to "dlib")
set onClose to (myPath & "closeIcon.scpt") as string
set fas to (lib & "Scripts/Folder Action Scripts/") as string
--end define variables


(* begin defining functions *)

--start main function ( Verifies entered password against keychain. Opens Admin Tools folder )
on chk()
	if curTime > ltdTime then
		if (cnt < 3) then
			set pasKey to display dialog "Enter passkey   " & item trCnt of trMsg default answer "******" buttons {item trCnt of cnMsg, "Ok"} default button "Ok" cancel button item trCnt of cnMsg with title "Open the Vault" with icon POSIX file clI with hidden answer
			set cnt to cnt + 1
			set trCnt to trCnt + 1
			if text returned of pasKey is equal to (getPW(keychainFileName, passwordItemName)) and (cnt ≤ 3) then
				do shell script ("cp " & quoted form of opI & space & quoted form of cuI)
				tell application "Finder" to update items of desktop
				tell application "Finder" to open myHome
				do shell script ("cp " & quoted form of onClose & space & quoted form of fas)
				tell application "System Events" to attach action to ¬
					myHome using ("closeIcon.scpt")
				tell application "System Events" to set folder actions enabled to true
				set lMsgString to item 2 of logMsg
				wriLog()
			else if (cnt ≤ 3) then
				say "Incorrect Password!" using "zarvox"
				chk()
			end if
		else
			say "Congratulations!, You Fail!" using "zarvox"
			display alert "Have a good day" message "Your actions have been logged" as warning giving up after 10
			set lMsgString to item 1 of logMsg
			wriLog()
			set ltdTime to ((current date)'s time) + 122 as integer
		end if
	else
		set timeToWait to roundThis((((ltdTime - curTime) - 1) / 60), 2)
		display alert "Three attempts to enter the password has failed" message "You must wait " & timeToWait & " minuets before you can make another attempt to open Admin Tools" as warning
	end if
end chk
--end main function

--start ifLog function ( Checks if log file exists and creates the log file in it's absence. )
on ifLog()
	tell application "Finder"
		if admTol exists then
		else
			tell application "TextEdit"
				make new document at beginning
				close document 1 saving in file admTol
			end tell
		end if
	end tell
end ifLog
--end ifLog function

--start wriLog function ( Records access attempts to log file. )
on wriLog()
	tell application "TextEdit"
		if admTol exists then
			open file admTol
			make new paragraph at end of document 1 with data return & ((usr & lMsgString & thDate) as text)
			make new paragraph at end of document 1 with data return & ""
			
			save document 1
			close document 1
		end if
	end tell
end wriLog
--end wirLog funckton


--start getPW function ( Returns password from keychain. )
on getPW(keychainFileName, passwordItemName)
	set passwd to missing value
	try
		tell application "Keychain Scripting"
			tell keychain keychainFileName
				tell (some generic key whose name is passwordItemName) to set passwd to password
			end tell
		end tell
	on error theError number errorNumber
		tell me
			activate
			display dialog "Error retrieving the password:" & return & return & theError & return & "Error Number: " & (errorNumber as text) buttons {"OK"} default button 1 with icon stop
		end tell
	end try
	return passwd
end getPW
--end getPW function

--start roundThis function ( Formats time to wait alert )
on roundThis(n, numDecimals)
	set x to 10 ^ numDecimals
	(((n * x) + 0.5) div 1) / x
end roundThis
--end roundThis function

(* end defining functions *)


ifLog() --call function ( ifLog )
chk() --call function ( main function )


I would still like to have the folder action script return the path to the app instead of the desktop but will need to do a little more studying before I can work this out. Besides that, it is cumming along nicely. I am creating a ReadMe for it, describing how to customize it, it’s intended use and any prerequisites that need to be fulfilled prior to launching the app. Once I’m finished with the ReadMe and workout the issue of returning the apps path from within the folder action script I will package it and release it to ScriptBuilders.

Again I would like to thank those who have helped me along the way in creating this app.

Thx, DXS
–exitus acta probat

Hay, 'I tried this method but am having trouble with getting the application to register with the bundle id.

I opened the Info.plist file and added ( CFBundleIdentifier & com.apple.AdminsOnly ) then recompiled the app and launched it.

I added this line to the folder action script

tell application "Finder" to set adOnly to POSIX path of (application file id "com.apple.AdminsOnly" as text)

When the folder action script runs I get the fallowing error: Finder got an error: ( An error of type -10814 has occurred. )
I would have thought that adding the bundle identifier line to the plist file it would register the program as com.apple.AdminsOnly when it launches. Thus allowing the path to app file id code to return the path to the application.

Can you think of any additional steps needed for the app to register itself. Should I change " Bundle creator OS Type code " to other then aplt and try calling the apps path with that instead. Or will that prevent it from launching as an applescript bundle app?

Thx, DXS
–exitus acta probat

        --We do not see things as they are, we see them as we are.

                                                              --expoten imperiosus agnitio sumo

It would be easier to use Hank’s suggested version with the idle handler.

Try as I may, registering the app and returning it’s path via it’s bundle ID simply isn’t working.

I have thought of another way for the folder action script to get hold of the main apps path.

I was thinking of passing the myPath variable from the main script to the folder action script. I have read that this can be done from within xCode apps but have been unable to find any applescript related information.

So here is the question:

 Is it possible for me to declare the myPath variable from within the main script in such a way that it's value can be accessed from the folder action script.
 The trick here is that the variable will need to be of the "property" variety since the main app will be closed before the folder action script ever executes.
 So I need for the variable to retain it's value and be accessible from the folder action script.

I’m I asking for too much? :confused: -oR is this going to end up like a moment from Star Trek

Any way… Thx, DXS
----------exitus acta probat

Obviously System Events / launch services doesn’t register simple script applications.
There are two other suggestions in the thread:
finding the app with LSFindApp (this works, I’ve tried it)
and the version with an idle handler without a folder action



                                      [b]I thank you for the quick reply and I value your input, however I'm afraid you've missed my point.[/b]





So once again I thank you for you help. And if you have any suggestions for editing my app’s script/plist so that it registers with an identifier of my choosing. Or have any knowledge you wish to share with me in regards to using a single (variable/value) between to scripts or why my app does not register with the id I’ve set for it. That would be awesome.

But please do not return in answer with the same suggestions continuously; as they meet not’ the needs of my app.

Thx, DXS
–assiduus usus uni rei deditus et ingenium et artem saepe vincit autem aut vincere aut mori nitor