 |
 |
Aplescript: Moving file to invisible folder
|
 |
|
 |
|
Grizzled Veteran
Join Date: Oct 1999
Location: Minneapolis
Status:
Offline
|
|
Is there a way to use applescript to move a file to an invisible folder. Ive tried naming the folder .Folder, and changing the invisibility bit, and both result in an error. i can post my code if is needed, but any way around this?
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
Try making the folder invisible in the terminal first.
e.g. mv myFolder .myFolder
or do you want to create the invisible folder dynamically as part of the script?
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Oct 1999
Location: Minneapolis
Status:
Offline
|
|
This is the script
Code:
on adding folder items to this_folder after receiving added_items
set Videofolder to ":Users:oscar:Documents:Stored_Folder:"
set PDFfolder to ":Users:oscar:Documents:PDFs:"
set TXTfolder to ":Users:oscar:Documents:"
tell application "Finder"
repeat with aFile in added_items
if name of aFile contains {".jpg"} or name of aFile contains {".mpeg"} or name of aFile contains {".png"} or name of aFile contains {".mpg"} or name of aFile contains {".tiff"} or name of aFile contains {".asf"} or name of aFile contains {".mov"} or name of aFile contains {".asf"} or name of aFile contains {".wmv"} or name of aFile contains {".avi"} then
tell application "Finder"
try
move file aFile to folder Videofolder with replacing
on error err
display dialog err
end try
end tell
end if
if name of aFile contains {".pdf"} then
tell application "Finder"
try
move file aFile to folder PDFfolder with replacing
on error err
display dialog err
end try
end tell
end if
if name of aFile contains {".mp3"} then
tell application "Finder"
try
open file aFile
move file aFile to trash
on error err
display dialog err
end try
end tell
end if
if name of aFile contains {".rtf"} or name of aFile contains {".doc"} or name of aFile contains {".txt"} then
tell application "Finder"
try
move file aFile to folder TXTfolder with replacing
on error err
display dialog err
end try
end tell
end if
end repeat
end tell
end adding folder items to
It's suppose to be attached to a folder action.
(Last edited by oscar; Dec 10, 2003 at 06:45 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
Sorry - I don't quite understand - where is the invisible folder in that script?
[edit]
do you mean that when you try to get the files moved to an invisible folder you get this:

|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Oct 1999
Location: Minneapolis
Status:
Offline
|
|
Originally posted by Diggory Laycock:
Sorry - I don't quite understand - where is the invisible folder in that script?
[edit]
do you mean that when you try to get the files moved to an invisible folder you get this:
Yes, the script craps out if the "sorted" folder is invisible. If it isnt, works like a charm
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
It would be a bit of an ugly hack - but you could unhide the folder before the move - then re-hide it again after the move.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2003
Location: Grand Rapids, MI
Status:
Offline
|
|
How about the following:
property video_extension_list_ : {"jpg", "png", "mpeg", "mpg", "tiff", "asf", "mov", "asf", "avi"}
property pdf_extension_list_ : {"pdf"}
property mp3_extension_list_ : {"mp3"}
property txt_extension_list_ : {"rtf", "doc", "txt"}
on adding folder items to this_folder after receiving added_items
tell application "Finder"
set Video_ to ":Users:oscar:Documents:Stored_Folder:" as string
set PDF_ to ":Users:oscar:Documents:PDFs:" as string
set TXT_ to ":Users:oscar:Documents:" as string
set Videofolder to folder Video_ as alias
set PDFfolder to folder PDF_ as alias
set TXTfolder to folder TXT_ as alias
repeat with aFile in added_items
if name extension of aFile is in video_extension_list_ then
try
move file aFile to folder Videofolder with replacing
on error err
display dialog err
end try
end if
if name extension of aFile is in pdf_extension_list_ then
try
move file aFile to folder PDFfolder with replacing
on error err
display dialog err
end try
end if
if name extension of aFile is in mp3_extension_list_ then
try
open file aFile
move file aFile to trash
on error err
display dialog err
end try
end if
if name extension of aFile is in txt_extension_list_ then
try
move file aFile to folder TXTfolder with replacing
on error err
display dialog err
end try
end if
end repeat
end tell
end adding folder items to
I don't think the fact that the folder is invisible is causing the problem, rather how you referenced the folder.
"set Videofolder to ":Users:oscar:Documents:Stored_Folder:"" is probably being set as a text string which won't do you much good. Notice that you can first set it to a string like you have, and then set that string to an alias (file/folder reference) in the Finder. (You'll need to do these "set's" inside the Finder tell block, otherwise you'll get an error when trying to use the "set Videofolder to folder Video_ as alias".
Hope this helps....
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2003
Location: Grand Rapids, MI
Status:
Offline
|
|
Actually, I discovered that if you are indeed trying to use an invisible folder, you'll get an error if you try using the following method:
tell application "Finder"
set TXT_ to ":Users:oscar:Documents:.my_invisible_folder" as string
set TXTfolder to folder TXT_ as alias
end tell
To prevent the error, you should use file instead of folder:
tell application "Finder"
set TXT_ to ":Users:oscar:Documents:.my_invisible_folder" as string
set TXTfolder to file TXT_ as alias
end tell
Not sure why this is, but....
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
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
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|