I have the following code to open the files, but they all open with iTunes:
tell application "Finder"
set the_files to get every file of folder ("Macintosh
SSD:Users:myusername:Desktop:DJ:Music:Sort")
end tell
repeat with theItem in the_files
tell application "QuickTime Player"
open theItem
end tell
end repeat
Thanks!
AS syntax can be very misleading. While your open command is inside a tell application … end tell block, that doesn’t necessarily mean it will be sent to that application. If the command’s direct parameter happens to be a reference to objects in another app (in this case, a reference to a document file object in Finder) AS will send it to that app instead.
Use set the_files to get every file of folder (…) as alias list. That will get you a list of AppleScript alias values, instead of a list of Finder references (which any app other than Finder wouldn’t understand anyway).
Related
I'm trying to do a very basic thing using Applescript but I'm having trouble. I am trying to create a very simple Applescript to just open a plain vanilla MP3 file on my desktop with QuickTime Player.
I want to use QuickTime and have it open so user can control it etc.
The basic problem is that the file name or folder path seems to be sometimes randomly causing problems especially when it has spaces in the name or the path folder names etc.
If I double click on any file they all open in QuickTime.
I created a very basic short audio file and saved it with a few different names like:
test1.mp3
test 1.mp3
this is a test.mp3
Then I created this very simple Applescript below.
generally = test1.mp3 will almost always open and start playing, however the other Versions with spaces in the title often produce and error (open thesong line fails i think) like:
The document “test1.mp3” could not be opened.
The file isn’t compatible with QuickTime Player.
error "QuickTime Player got an error: Can’t get document 1. Invalid index." number -1719 from document 1
think this is because it can't open the file.
Any help would be appreciated.
Applescript ...
tell application "Finder"
--varied attempts like this...
set thesong to "drive:Users:me:Desktop:music:test1.mp3" as string
set thesong to "drive:Users:me:Desktop:music:test1.mp3"
set thesong to "drive:Users:me:Desktop:music:this is an audio test.mp3" as string
set thesong to "drive:Users:me:Desktop:test1.mp3" as string
end tell
tell application "QuickTime Player"
activate
open thesong
play document 1
end tell
Also I tried adding delays thinking that QuickTime needed time to open before open / play song - but still have random fails...
tell application "QuickTime Player"
activate
delay 3
open thesong
delay 3
play document 1
end tell
The Finder is not needed and the delays are not needed either.
Assuming the file is on the desktop create a relative HFS path and add the alias keyword after the open command
set theSong to (path to desktop as text) & "test1.mp3"
tell application "QuickTime Player"
activate
set activeDocument to open alias theSong
play activeDocument
end tell
If the file is in the folder music on the desktop the path is
set theSong to (path to desktop as text) & "music:test1.mp3"
In AppleScript, there are differences between a string, a POSIX file («class furl») , and an alias.
When you do set thesong to "drive:Users:me:Desktop:music:test1.mp3" as string that creates a string, which is just plain text. QuickTime Player's open command requires either a POSIX file or an alias, which is why you get an error message (it doesn't know what to do with a plain text string).
While you ultimately need to end up with a POSIX file or alias, you can start with a string and then coerce it to the type you want.
Either of the open commands below should work:
set posixFile to "/Users/you/Desktop/file.mp3" as POSIX file
set aliasFile to ":Users:you:Desktop:file.mp3" as alias
tell app "QuickTime Player"
set theDoc to open posixFile
-- or set theDoc to open aliasFile
play theDoc
end tell
I'm new to AppleScript and not programmer, so I'm hoping someone can help me out...
I want to get the current track path in iTunes and open the file in another program [Riffstation]
seems like this should work, but it doesn't:
tell application "iTunes"
set songLocation to get location of current track
end tell
tell application "Riffstation"
open songLocation
end tell
any help would be greatly appreciated!!!
Riffstation doesn't support AppleScript so you have to ask the Finder to open the file and pass it to Riffstation
tell application "iTunes"
set songLocation to get location of current track
end tell
tell application "Finder" to open songLocation using application file id "com.SonicLadder.Riffstation"
If you want to ignore .m4p files use
tell application "iTunes" to set {location:songLocation, kind:songKind} to current track
if songKind is not "Protected AAC audio file" then
tell application "Finder" to open songLocation using application file id "com.SonicLadder.Riffstation"
end if
I need to write an AppleScript so that it will open QuickTime Player, play the movie from the specific file, and set it to loop in full screen. Help please I am a noob at writing AppleScripts.
This is what I have so far but it does not seem to work. :(
tell application "QuickTime Player"
open file "Macintosh HDN:Users:lalayana:Downloads:TV Master Keynote.m4v"
set the looping of movie 1 to true
play movie 1
end tell
The easiest way to do it is probably to assign the value returned by open file to a variable, and then tell that variable (that is, tell that movie) to do what it needs to do.
tell application "QuickTime Player"
set theMovie to open file "Macintosh HDN:Users:lalayana:Downloads:TV Master Keynote.m4v"
tell theMovie
set the presenting to true
set the looping to true
play
end tell
--use this to see what properties can be modified
--get the properties of theMovie
end tell
You can uncomment get the properties of theMovie to see what properties are available to modify.
If that doesn’t work for you, you’ll also need to specify exactly what you mean by “it does not seem to work”. That is, what error occurs, if an error occurs, or what happens differently than what you expect. I’ve verified that the above does work with a movie on my end.
I just had this problem and the solution above did not work for my apple computer, so I modified the script to get it to work. I wanted to the script to launch on boot, which I accomplished by going to System Preferences -> Users -> Login Items.
tell application "QuickTime Player"
set theMovie to open file "Users:danielmcclane:Downloads:startvideo.mov"
tell theMovie
set the looping of theMovie to true
set the present of theMovie to true
play
end tell
end tell
This worked for me. I use it to play video art pieces at the museum I work at. It works.
tell application "QuickTime Player"
activate
open alias "Users:ebowen:Desktop:MOUND_1.32GB_h264.mov"
play the front document
end tell
tell application "System Events" to tell process "QuickTime Player"
set frontmost to true
tell menu bar item 5 of menu bar 1
click menu item "Enter Full Screen" of menu 1
click menu item "Loop" of menu 1
end tell
end tell
Good morning,
I am trying to write an AppleScript that I can run that will send all the files on my desktop to Evernote, and then delete the files. My code to date is:
on run {input}
tell application "Finder"
select every file of desktop
end tell
tell application "Evernote"
repeat with SelectedFile in input
try
create note from file SelectedFile notebook "Auto Import"
end try
end repeat
end tell
tell application "Finder"
delete every file of desktop
end tell
end run
If I run this then the first and last 'tell' work fine (ie. the script highlights then deletes all the files on the desktop), but the middle 'tell' doesn't do anything.
However, if I manually highlight all the files on the desktop and then run just the middle 'tell' then it imports fine - each item into a separate note as intended.
As you can tell, I am new to AppleScript - I suspect I need to put the selected files in an array of some sort, but can't figure it out. Help!
Many thanks
Rich
Your code fails because there is no relation between your input variable and the selection of files via Finder – which means that your list is empty, and Evernote is not processing anything at all. You have obfuscated the problem by wrapping the Evernote import command in a try block without any error processing, which means all errors just go unnoticed (to avoid this kind of problem, it is good practice to always log the error message in an on error clause, if nothing else).
Also, you don’t actually need to select files on the Desktop via AppleScript to process them. The following code will grab all visible files (excluding pseudo-files like packages / apps):
tell application "System Events"
set desktopFiles to every disk item of (desktop folder of user domain) whose visible is true and class is file
end tell
Pass the list you retrieved that way to Evernote for processing:
repeat with aFile in desktopFiles as list
try
tell application "Evernote" to create note from file (aFile as alias) notebook "Auto Import"
tell application "System Events" to delete aFile
on error errorMessage
log errorMessage
end try
end repeat
and you are good to go.
Note that by judiciously placing the deletion command (right after the import command, inside the try block, inside the loop over all files), you make sure it is only called if Evernote does not error on import while avoiding having to iterate over the files several times.
A final note: you don’t have to use the block syntax for tell statements if there is only one command to execute – using tell <target> to <command> is easier and will keep you out of nested context hell.
Thanks #adayzone for corrections on list handling and alias coercion
Try
tell application "System Events" to set xxx to get every file of (desktop folder of user domain) whose visible is true
repeat with i from 1 to count of xxx
set SelectedFile to item i of xxx as alias
try
tell application "Evernote" to create note from file SelectedFile notebook "Auto Import"
tell application "Finder" to delete SelectedFile
end try
end repeat
Thanks #fanaugen
I just need a snippet to open and then save a file. It's an illustrator PDF with linked artwork, problem being the linked files do not update unless I open then save the file and I am having to do this sooooo many times it's making my brain explode.
Should be straightforward. I tested the following snippet in Illustrator CS3 (13.0.2) on Mac OS X 10.6.8.
set theFiles to choose file with prompt "Select the files" of type {"pdf"} with multiple selections allowed
tell application "Adobe Illustrator"
repeat with theFile in theFiles
open theFile without dialogs
save current document in theFile as pdf
end repeat
end tell
The choose file command (which prompts the user to locate one or more files) is just one way of obtaining a list of files. You could just as well use
tell app "Finder" to set theFiles to every document file of folder "Macintosh HD:Full:Path:To:Your:Folder" whose file type begins with "pdf"
if you want to get all PDF files inside a specific folder.