Script to run a file on login

Hi,

I’m no “coder” at all, so if anyone can create this for me, it would be awesome :slight_smile:

Here’s what I want to do:
I want to open an audio file with Quicktime
Then I want that file to be set to Loop (Quicktime > View > Loop)
Then I want Quicktime to start playing that file.
Finally, I want to minimize that window.

I want to have a script that I can import into the Automator so I can then create an app that runs when I restart my computer.

Is this possible and easy to accomplish?
As I mentioned, I’m no coder and my Automator knowledge is hyper limited, if any at all.
I tried using the “Watch Me Do” feature, but it didn’t work as expected.

Any help would be greatly appreciated! :slight_smile:

The script included below should do what you want. I’m not familiar with Automator but would expect it to work.

set mediaFile to (choose file) as text

tell application "QuickTime Player"
	activate
	tell (open file mediaFile)
		set looping to true
		play
	end tell
	delay 1 -- test different values  
	set miniaturized of every window to true
end tell

Thanks for the quick and helpful reply! :slight_smile:
It worked the way it is, at least as an Apple Script, still have to try it as an Automator app.
Now how can I make it pick the file automatically?
The file is:
/Users/3ple/My Files/Files/*Mono Sine.wav

How can I implement that so that when the app runs on login, it picks the file for me so I don’t have to do anything?

You would do that as follows. The script will throw an error if the media file can’t be found. Does the file name actually begin with a “*”

set mediaFile to (POSIX file "/Users/3ple/My Files/Files/*Mono Sine.wav") as alias

tell application "QuickTime Player"
	activate
	tell (open mediaFile)
		set looping to true
		play
	end tell
	delay 1 -- test different values 
	set miniaturized of every window to true
end tell

Thank you again for your help!
Yes, the file starts with *
I usually rename files like that when I want them at the top the list of files inside a folder.

So I tried the script, but now I’m getting the following error that shows at the bottom of the scripter:
error “QuickTime Player got an error: Can’t get file (alias "3ple:Users:3ple:My Files:Files:*Mono Sine.wav").” number -1728 from file (alias “3ple:Users:3ple:My Files:Files:*Mono Sine.wav”)

I even tried renaming the file, removing the * and then changing the code by also removing the * but it behaves the same way. :confused:

I’ve edited the above script. Please give that another try.

same thing :frowning:

The thing is that when it shows the error, it highlights the word “alias”.

Now the error is:
error “Can’t make file "3ple:Users:3ple:My Files:Files:*Mono Sine.wav" into type alias.” number -1700 from file “3ple:Users:3ple:My Files:Files:*Mono Sine.wav” to alias

Notice that it changed from -1728 to -1700 (don’t know what that means, but it’s different now, in case that gives you any clue of what’s happening).
Also, it went from “can’t get file” to “can’t make” file.

Here’s the other one so you can see them “side by side”
error “QuickTime Player got an error: Can’t get file (alias "3ple:Users:3ple:My Files:Files:*Mono Sine.wav").” number -1728 from file (alias “3ple:Users:3ple:My Files:Files:*Mono Sine.wav”)

It seems that the issue is with the “alias” part of the code…

My bad… I was using the code with the *, but forgot to change the filename back to *
It’s working now when I use the Automator :slight_smile:

Now the issue is that when I restart the computer, it indeed runs the application, but it doesn’t hit Play or activates the loop. It does minimize the window though.
I’m guessing this has probably to do with the delay parameter, maybe?
Does the 1 mean 1 second? I will try with 3 and 5, see what happens.

No luck.
Increased it to 5, the window stays opened, but does nothing, then minimizes.
Again, it works when I click the Automator’s app, it just doesn’t work when I restart the computer and I set it to run on login.

Not a big deal. This is already a great help. It saves me some time :slight_smile:

I really appreciate your time and help!!
Enjoy the rest of your week! :slight_smile:

I’m sorry to hear that didn’t work.

New approach of Apple is: every application should coerce HFS path to its own file reference, instead of using AppleScript aliases. So, your code should work in this form:


set mediaHFS to ((path to home folder) as text) & "3ple:My Files:Files:Mono Sine.wav" -- EDITED

tell application "QuickTime Player"
	activate
	tell (open file mediaHFS) -- EDITED
		set looping to true
		play
	end tell
	delay 1 -- test different values 
	set miniaturized of every window to true
end tell

.

Automator doesn’t create applications. It runs and creates only workflows and services. You should save the script above as application from Save menu of script editor. Then, you can add this application to Login Items location of your Mac. Manually, or programatically.

NOTE: on the last OSX versions you can add login items only manually thru Users & Groups pane of System Preferences.

On the old OSX versions following script programatically adds the application to login items:


my addAppToLoginItemsAfterCheckingInOnes("BBEdit")

on addAppToLoginItemsAfterCheckingInOnes(appName)
	try
		set appPath to (path to application appName)
	on error
		display notification "Application with this name NOT founded" sound name "Frog"
		return
	end try
	tell application "System Events"
		try
			set allLoginItems to name of every login item as string
		on error
			set allLoginItems to {}
		end try
		if appName is not in allLoginItems then tell application "System Events" to make login item at end with properties {path:appPath, hidden:false}
	end tell
end addAppToLoginItemsAfterCheckingInOnes