Select file with certain extension located in the desktop folder

Hello,

I am trying to show the user the files listed in the desktop folder and I am prompting for him to tell which movie file does he want to select from the desktop folder.

I am difficulties, can someone help me? MANY THANKS!

Daniel

set VidExtension to {"mov", "mp4"}
set theTargetFolder to ((path to desktop folder)) as string

tell application "Finder"
	set Names to paragraphs of (read (choose file of theTargetFolder whose name extension is in VidExtension with prompt "Please select the correct movie file "))
	repeat with nextLine in Names
		if length of nextLine is greater than 0 then
			--Do something with the next name, which is stored in "nextLine"
		end if
	end repeat
end tell

I have no idea what you are going to read from a movie file. I guess you simply mean

set VidExtension to {"mov", "mp4"}
set selectedFile to choose file with prompt "Select File" default location (path to desktop) of type VidExtension

Many thanks Stefan,

I am trying to replace this step

	set xlsFilePath to (path to desktop as text) & "DataSheet.xlsx"
	tell application "Microsoft Excel" to open file xlsFilePath
	delay 2

by this one where the user is to be asked to select an excel file.

set VidExtension to {"xlsx", "xls"}
	set selectedFile to choose file with prompt "Select File" default location (path to desktop) of type VidExtension
	tell application "Microsoft Excel" to open file selectedFile
	delay 2

Unfortunately the new script is giving the following error message

error “Microsoft Excel got an error: Can’t get file (alias "Macintosh HD:Users:Username:Desktop:Datasheet.xlsx").” number -1728 from file (alias “Macintosh HD:Users:Username:Desktop:Datasheet.xlsx”)

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) dimanche 25 juin 2017 11:49:52

Many thanks - it work :slight_smile:

It doesn’t fool the app. It’s a file specifier object that contains an alias to be resolved into an file object. The eventual object used by the app after resolving is actually an file object.

It seems that the error message disagree with your statement.

[format]error “Microsoft Excel got an error: Can’t get file (alias "Macintosh HD:Users:Username:Desktop:Datasheet.xlsx").” number -1728 from file (alias “Macintosh HD:Users:Username:Desktop:Datasheet.xlsx”)[/format]

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) dimanche 25 juin 2017 20:58:41

That only means that the application doesn’t have any handler installed to resolve the object. In AE terms that means that the app is missing an object accessor function for that specific from-to specifier. It doesn’t disagree with what I was saying, it only proves that it lacks a specific handler.