1

次のように、1 つのランダムなファイルを正常に開いています。

tell application "Finder"
   open some file of folder "HD:random"
end tell

フォルダー内の 3 つのランダムなファイルを開きたいと思います。3つの異なるもの。Applescript を 3 回実行すると、時々同じものが得られます。

ありがとう!

4

1 に答える 1

1

「いくつかのファイル」を使用する1つの方法は次のとおりです...

set theNumber to 3
set theFolder to choose folder

set theFiles to {}
repeat
    tell application "Finder" to set aFile to (some file of theFolder) as text
    if aFile is not in theFiles then
        set end of theFiles to aFile
        tell application "Finder" to open file aFile
    end if
    if (count of theFiles) is equal to theNumber then exit repeat
end repeat

乱数を使用する別の方法は次のとおりです...

set theNumber to 3
set theFolder to choose folder

tell application "Finder" to set theFiles to files of theFolder
set fileCount to count of theFiles
if fileCount is less than theNumber then error "I couldn't find " & (theNumber as text) & " files in the chosen folder."

set randomNumbers to {}
repeat
    set aNum to random number from 1 to fileCount
    if aNum is not in randomNumbers then
        set end of randomNumbers to aNum
        tell application "Finder" to open (item aNum of theFiles)
    end if
    if (count of randomNumbers) is equal to theNumber then exit repeat
end repeat
于 2012-09-11T22:15:06.373 に答える