C-Command Software Forum

How to get records at random?

In order to remember old-posts, I show 4 posts (selected at random from all posts) in top page of my blog via :
$newquery = new WP_Query(‘showposts=4&orderby=rand’).

How to write an Applescript to do the same function in EF?
For example, it shows four records (selected at random from ALL records) with title in Records list windows.

I tried to follow examples of EF scripts, but they seem to concern “selected” records and not to “selecting”.

I appreciate to get any suggestion or advice.

The selected records property is settable. For example:

tell application "EagleFiler"
    tell library document 1
        set _records to {library record id 157}
    end tell
    tell browser window 1
        set selected records to _records
    end tell
end tell

Thank you for kind reply as always.

I CAN get record via changing library record id from 157. Selected record (in Record list window) appears with auto-scroll and is highlighted with grey color. Great !!

Two more questions:

  1. How to add such an id number on each record in EF?
    In alphabetical way, with first-come and first-import style or under other rule? Some ids seem to miss records.

  2. Maximum number of id is total number of records?
    Scope of random id generator needs this value.

best regards,

Each record has an id already; that’s how AppleScript works. The id 157 was just an example. The IDs are not necessarily consecutive.

You can also get records by index. To find out how many there are:

get count of library records

To get one by index:

get library record 1

To get one by filename:

get library record "MyFile.webarchive"

Thank you for your example codes.

I will try to combine them up to target Script.

I can get record at random from oldest 1/10 of all records.

set _count to get count of library records
set _num to random number from 1 to round (_count / 10)
set _myrecord to get library record _num
set _title to _myrecord’s title

By the way, _count is 2 even when the library has NO record.
Index number 1 and 2 may correspond to [Records], [Files] or [Trash] ?

I will try to make more complicated script from now.

Thank you for your advice again.

Yes, the root folder (Files) and the trash count as records.