Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Aplescript: Moving file to invisible folder

Aplescript: Moving file to invisible folder
Thread Tools
Grizzled Veteran
Join Date: Oct 1999
Location: Minneapolis
Status: Offline
Reply With Quote
Dec 9, 2003, 04:40 PM
 
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
Reply With Quote
Dec 9, 2003, 06:29 PM
 
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?
     
oscar  (op)
Grizzled Veteran
Join Date: Oct 1999
Location: Minneapolis
Status: Offline
Reply With Quote
Dec 9, 2003, 09:41 PM
 
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
Reply With Quote
Dec 10, 2003, 07:06 AM
 
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:

     
oscar  (op)
Grizzled Veteran
Join Date: Oct 1999
Location: Minneapolis
Status: Offline
Reply With Quote
Dec 10, 2003, 08:16 AM
 
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
Reply With Quote
Dec 10, 2003, 10:04 AM
 
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
Reply With Quote
Dec 13, 2003, 12:55 PM
 
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
Reply With Quote
Dec 19, 2003, 07:29 AM
 
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....
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:32 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2