Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

System Events: get file names in directory

 
   Mac (Home) -> Apple Scripts RSS
Next:  Office 2004 Setup Assistant Freezes  
Author Message
Martin Krischik

External


Since: Sep 27, 2008
Posts: 4



(Msg. 1) Posted: Mon Jul 27, 2009 7:11 pm
Post subject: System Events: get file names in directory
Archived from groups: alt>comp>lang>applescript (more info?)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I relay tried and googled it all but I just can't get "System Events" to
get me the file names of a folder. Here the snippet I got:

tell application "System Events"
-- set Current_Folder to POSIX file Current_Path
set Current_Folder to POSIX file "/Users/martin"
set Backup_Files to get the name of every item of Current_Folder --
whose name starts with ("martin")
end tell

Current_Path is of course a valid posix path. It seems to be some data
type problem. And the error messages are not at all helpful:

System Events got an error: Can't make every item of file "Macintosh
HD:Users:martin" into type reference.

Is there any full features documentation of System Events?

Thanks for any help.

Martin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFKbd+iijwKaHyem9cRAi5JAJ0YBPRiVGzWjZO4a8vFQwpbTdKQfQCfV83G
EN7BeZi0OxQyEbPq6WdVi6c=
=OgFQ
-----END PGP SIGNATURE-----
Back to top
Login to vote
Michelle Steiner

External


Since: Aug 30, 2005
Posts: 1352



(Msg. 2) Posted: Tue Jul 28, 2009 5:15 am
Post subject: Re: System Events: get file names in directory [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

This message is not archived
Back to top
Login to vote
Jolly Roger

External


Since: Nov 05, 2007
Posts: 1219



(Msg. 3) Posted: Tue Jul 28, 2009 10:20 am
Post subject: Re: System Events: get file names in directory [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <5m31k6-ojc2.ln1 DeleteThis @macpro.krischik.com>,
Martin Krischik <krischik DeleteThis @me.com> wrote:

> I relay tried and googled it all but I just can't get "System Events" to
> get me the file names of a folder. Here the snippet I got:
>
> tell application "System Events"
> -- set Current_Folder to POSIX file Current_Path
> set Current_Folder to POSIX file "/Users/martin"

As a general rule, you should only include commands that are directly
attributable to an application in the application's "tell" block. So I
advise you to move the Current_Folder assignment out of the tell block.

Also, if you want an alias to the home folder, a far better way to get
it is:

set Current_Folder to the path to the home folder

That way, no matter what the path, your script will always be right.
Again, leave this statement outside of the tell block.

> set Backup_Files to get the name of every item of Current_Folder --
> whose name starts with ("martin")
> end tell

Try this instead:

tell application "System Events"
set Backup_Files to the name of every item in Current_Folder
end tell

Note that using the keyword "item" means the resulting list will contain
files *and* folders. To get a list of only files, replace "items" with
"files" above.

> Current_Path is of course a valid posix path. It seems to be some data
> type problem. And the error messages are not at all helpful:
>
> System Events got an error: Canšt make every item of file "Macintosh
> HD:Users:martin" into type reference.
>
> Is there any full features documentation of System Events?

More than the dictionary you can read in Script Editor? Not sure.

I've always used the "list folder" command from Standard Additions.
Lately it's apparently been deprecated, but it still works. What I like
about the Standard Additions method is you don't need a tell block at
all:

set Backup_Files to list folder the path to the home folder

--
Send responses to the relevant news group rather than email to me.
E-mail sent to this address may be devoured by my very hungry SPAM
filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google
Groups. Use a real news client if you want me to see your posts.

JR
Back to top
Login to vote
Jolly Roger

External


Since: Nov 05, 2007
Posts: 1219



(Msg. 4) Posted: Tue Jul 28, 2009 10:20 am
Post subject: Re: System Events: get file names in directory [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <michelle-D00C8D.05151528072009.RemoveThis@nothing.attdns.com>,
Michelle Steiner <michelle.RemoveThis@michelle.org> wrote:

> In article <5m31k6-ojc2.ln1.RemoveThis@macpro.krischik.com>,
> Martin Krischik <krischik.RemoveThis@me.com> wrote:
>
> > Thanks for any help.
>
> This works for me:
>
> set current_folder to (path to desktop as text) & "aaaa" as alias
> tell application "System Events"
> set Backup_Files to name of files of current_folder whose name starts
> with "picture"
> end tell

Note that this will only return *files* and not *folders*. If you want
both, replace "files" with "items".

It wasn't clear from Martin's initial post which he really wanted,
because he stated he wanted "file names of a folder", but used the
keyword "items" in his script, which would have returned files *and*
folders.

--
Send responses to the relevant news group rather than email to me.
E-mail sent to this address may be devoured by my very hungry SPAM
filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google
Groups. Use a real news client if you want me to see your posts.

JR
Back to top
Login to vote
Michelle Steiner

External


Since: Aug 30, 2005
Posts: 1352



(Msg. 5) Posted: Tue Jul 28, 2009 10:20 am
Post subject: Re: System Events: get file names in directory [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

This message is not archived
Back to top
Login to vote
Martin Krischik

External


Since: Sep 27, 2008
Posts: 4



(Msg. 6) Posted: Tue Jul 28, 2009 9:48 pm
Post subject: Re: System Events: get file names in directory [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jolly Roger schrieb:
> In article <5m31k6-ojc2.ln1 RemoveThis @macpro.krischik.com>,
> Martin Krischik <krischik RemoveThis @me.com> wrote:
>
>> I relay tried and googled it all but I just can't get "System Events" to
>> get me the file names of a folder. Here the snippet I got:
>>
>> tell application "System Events"
>> -- set Current_Folder to POSIX file Current_Path
>> set Current_Folder to POSIX file "/Users/martin"
>
> As a general rule, you should only include commands that are directly
> attributable to an application in the application's "tell" block. So I
> advise you to move the Current_Folder assignment out of the tell block.

Ok,
> Also, if you want an alias to the home folder, a far better way to get
> it is:
>
> set Current_Folder to the path to the home folder

The line commented out is the one I really want the other one is just
there to simplyfy the test until it works out

>> set Backup_Files to get the name of every item of Current_Folder --
>> whose name starts with ("martin")
>> end tell
>
> Try this instead:
>
> tell application "System Events"
> set Backup_Files to the name of every item in Current_Folder
> end tell

Sans "get". I see...

> Note that using the keyword "item" means the resulting list will contain
> files *and* folders. To get a list of only files, replace "items" with
> "files" above.

Thanks - I will use files then!

>> Current_Path is of course a valid posix path. It seems to be some data
>> type problem. And the error messages are not at all helpful:
>>
>> System Events got an error: Canšt make every item of file "Macintosh
>> HD:Users:martin" into type reference.
>>
>> Is there any full features documentation of System Events?
>
> More than the dictionary you can read in Script Editor? Not sure.

The dictionary does not tell you the exact syntax. I begin to wonder if
AppleScript is a read only language Wink.

> I've always used the "list folder" command from Standard Additions.
> Lately it's apparently been deprecated, but it still works.

I saw that as well. And since it was depreciated did not us it.

Thank

Martin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFKb1YWijwKaHyem9cRAg4eAKCIMEHDqkKJC2cGKeLuTYdilWKQSQCfUIFh
1ksRXjPN/PPr5bdiZVaFy0w=
=XDqp
-----END PGP SIGNATURE-----
Back to top
Login to vote
Jolly Roger

External


Since: Nov 05, 2007
Posts: 1219



(Msg. 7) Posted: Wed Jul 29, 2009 6:52 pm
Post subject: Re: System Events: get file names in directory [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <s914k6-lf91.ln1.RemoveThis@macpro.krischik.com>,
Martin Krischik <krischik.RemoveThis@me.com> wrote:

> > Also, if you want an alias to the home folder, a far better way to get
> > it is:
> >
> > set Current_Folder to the path to the home folder
>
> The line commented out is the one I really want the other one is just
> there to simplyfy the test until it works out

Ok, but I still recommend you use "path to home folder" because it will
always find the home folder regardless of the path.

--
Send responses to the relevant news group rather than email to me.
E-mail sent to this address may be devoured by my very hungry SPAM
filter. Due to Google's refusal to prevent spammers from posting
messages through their servers, I often ignore posts from Google
Groups. Use a real news client if you want me to see your posts.

JR
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Selected events/todos in iCal - I'm fairly new to AppleScript and I'm trying to write a script for iCal that performs actions on the selected iCal item. From my previous knowledge of AppleScript, I assumed this would be fairly easy to do, but there doesn't seem to be a way to get the..

Help with System Preferences script - From an obvious novice: I'd like to have a script for my wife that will 1.open the display preferences and 2.select a certain screen resolution and colors ( i.e. 256/thousands/millions). I can get as far as opening the preferences pane but I can't....

Editing system files via scripts - I want to edit the printer.conf file for cups. I need to do it dynamically. where do i find example files on editing text files and changing to sudo mode? Regards Isak

File Reference - Can anyone tell me why this works: set fileName to "foo" set filePath to "HD:Users:abc:" set theFile to filePath & fileName set fileRef to open for access theFile with write permission set eof fileRef to 0 write "test" ...

Zip a file - Hey, Everyone. I want to create an applescript that zips a file and plunks it in an "Archieve" folder. I could uses automator, but it wont pipe the name of the file and prepend it to the new zip file. I don't know how to run a zip command fr...
       Mac (Home) -> Apple Scripts All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
 Linux Forums
  Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact