![]() |
I have a little Applescript app I made that checks for then deletes a file from the Desktop:
Code:
tell application "Finder"This works well however I need it to run in the background and have a quit menu, or automatically quit when i need to log out or restart. Can anybody tell me how to make my script behave that way, or a better way to have a file regularly deleted? By the way, I tried using this as a Folder Action Script but it doesn't work. I have no idea why. Thanks |
You could have this:
Code:
tell application "Finder" |
Thanks for the reply!
I do use the "do shell script "sleep 30"" command to avoid using excess cpu time, and I save the script as "stay open." But whenever i log out or restart the app won't quit automatically and I have to either force quit it or use command-period. Thanks for the tip about Dockless! I'll give that a try :) |
try to run applescript to delete user profile
I am very new to OSX,
i try these code: tell application "Finder" activate if file "Macintosh HD:Users:user:Desktop:filename" exists then delete file "Macintosh HD:Users:user:Desktop:filename" end if end tell but the files on the desktop still desktop, can you advise |
You might want to try using Lingon to do this if you are running Leopard. You can easily set it to run when a file or folder changes, thereby keeping a load off your cpu. It uses the built-in launchd, which is what the OS uses to manage background processes and other things that open automatically. I don't know how well it would work with an AppleScript. If you know how, I would use a bash script. I only know a little about bash scripts, so maybe someone else can help whip up a simple one for you. Then again, an AppleScript may work just fine.
|
Are you including the extension in the filename? Just to be clear, "user" should be your short username.
|
I just type filename without any extension and "user" I did put the username.
|
Quote:
1. It is bad practice to hardwire a path. The script would fail, for instance, if you ran it on a clone. Also, for this purpose you shouldn't need to supply a path at all. 2. Using a repeat loop, you shouldn't have saved as "Stay Open" - the app will stay open as long as the loop doesn't exit. Also, your script contains nothing to tell a "Stay Open" app to close. Rather than complicating the loop, use an idle handler instead. Save the following as a "Stay Open" app... Code:
on idleCode:
on quit |
Quote:
tell application "Finder" to if exists file ((path to desktop folder as string) & "dummy.rtf") then beep 3 You can see all the locations you can use with "path to" in Dictionary > Standard Additions. To know whether you need an extension or not use Finder's 'Get Info' to see the full name. Whether an extension is 'hidden' or not is irrelevant. |
It was my mistakes, i am too influenced by MS DOS, i put the wrong file extension. Sorry guys
It script is works however, how do I select all files and all file extension type like MS dos *.* and folders on the desktop? Please advice |
Quote:
In Script Editor you will learn a lot by browsing through dictionaries. A search in the Finder Dictionary for, say, "name", "extension", etc will show you all sorts of variations and coercions, for instance... tell application "Finder" to get name of every file in desktop or shortened to tell application "Finder" to get name of files will give a list of the names of all files on the desktop whether they have or don't have an extension, showing or hidden. tell application "Finder" to select every file in desktop or tell application "Finder" to select files will do the obvious. Be aware, though, that selecting an item before applying a command to it is very bad practice - if you can identify the item(s) sufficiently to select it/them you can work on it/them directly without selecting it/them first. |
Thanks guys , I have finally understand how applescript works and I think Apple is better, after learning how to operate Imac and certain modification.
I modify these script and it works perfectly.
|
You're coming along. You didn't notice, though, that in my previous posts I showed you that
Code:
items in desktop andevery item of folder "Desktop" of folder "user" of folder "Users" of folder "Macintosh HD" Likewise Code:
items in (path to documents folder from user domain) andevery item of folder "Documents" of folder "user" of folder "Users" of folder "Macintosh HD" (Look in the 'Standard Additions' dictionary for details about "path to"). BUT it's not just a question of being shorter - it's also (as I told you earlier) that "hard wiring" (giving the absolute path) is bad scripting. You should NOT use the name of a volume, or that script will fail if run from elsewhere or will do something you didn't want. ...and you might decide one day that you're tired of that Oh-so-boring name, "Macintosh HD" and change it. Have to modify all your scripts - Oh dear! :) Study the dictionaries. Have fun! |
How to faster the OSX logon to Window 2003 domain
Anyone of you have any ideal faster your logon into the WIndow 2003 domain.
|
Quote:
On the other hand we need to join the AD domain, I have blind the OSX with AD but I can't logon to AD with my domain user account. Please advise |
James
The questions you are now asking bear no relation to the title of this thread. If you want to get the attention of those who may be able to help you, start a new thread. =-=-=-=- You didn't respond to my last post, so obviously it was of no use to you. Sorry. |
Sorry Andreas for the previous questions, can you assist me how to write a apple script, if the current user is not equal to admin and certain users in Mac User profile then delete the user's folder (user profile) i wrote a script and obviously it does not work, please bear with me
Quote:
|
James, you won't like my answer...
I will NOT offer you any help with doing what you are trying to do because it is HIGHLY DANGEROUS. You are heading towards locking yourself out of your own Mac. Be thankful that your bit of code is gibberish and cannot work. Sorry, but I draw the line at helping to assist a suicide! Apple supplies you with System Preferences > Accounts to make alterations to accounts in a SAFE way. Once again I see that you have taken no notice of my repeated advice NOT to use the name of a volume in a path. James, a good rule to follow is not to ask for advice from anyone whose advice you don't want to take! :) |
I would do something like this...
Code:
#!/bin/bashAlso my syntax can be slightly off I am just now starting to teach myself looping. Also, James, deleting the user's folder does not delete the user, they are still in the directory services BSD database on the machine locally. If you want to script out deleting accounts you would have to use the dscl command. |
Why don't you just use the guest account. I am assuming that you are using Leopard.
|
Quote:
While that double-bracketed test [[ -e $file ]] eliminates the need to quote the $file variable, elsewhere in the do loop quotes will likely be needed. So rm -rf $file should be rm -rf "$file" OTOH, the quotes where list was defined aren't needed: list=$HOME/Desktop/* Of course, that script (as written anyway) simply deletes everything there, so it could be shortened by eliminating the looping and testing altogether: rm -rf ~/Desktop/* but that won't notify us if the Desktop was empty (of visible items). |
Quote:
Ah you are right the only time I need to quote it is if there are multiple paths to a variable...I think. |
Quote:
Essentially, we should *always* ensure they are accounted for... somehow. In the [[ ]] form of test, the shell provides quoting behind the scenes. Another method is using the ability of some commands to append null chars (or accept null chars) as the 'filename delimiter'. Most common being: find blah blah -print0 |xargs -0 blah We also had a thread somewhere where we removed the 'space' from the IFS variable (so that newlines became the main delimiter). |
tell application "Finder"
try delete (every item of folder "Desktop" of folder "user" of folder "Users" of folder "Macintosh HD") end try try delete (every item of folder "Documents" of folder "user" of folder "Users" of folder "Macintosh HD") end try try delete (every item of folder "Downloads" of folder "user" of folder "Users" of folder "Macintosh HD") end try empty trash end tell i like this script, how can i modify it to select all user except administrator to replace "user" in this scriopt. |
how to select all users except administrator without having to type all the users name under "user" in this script?
|
| All times are GMT -5. The time now is 02:11 PM. |
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.