I want an Applescript that refreshes a certain song in iTunes from a file. To address the file in iTunes, i have only the path to the file.
I tried it on my own with "refresh" and "file track" but I'm a total newbie on AppleScript so I didn't got anything to work.
I'm an Applescript noob as well, but I figured out on my own!
It's good to know that you can open the iTunes dictionary and browse for things.
Applescript is a strange language, but a lot of it can be guessed from normal English.
Problems with my solution:
I can't figure out what the location alias is about, so I'm not sure what to enter here.
For some reason it does work with selection, but not with library playlist.
My code:
tell application "iTunes"
set the_location to location of current track
repeat with this_track in selection
if (get location of this_track) is the_location then
refresh this_track
log "match"
end if
end repeat
end tell
Related
trying to reproduce right-click context menu on my Mac.
I found such an article:
https://beebom.com/how-right-click-using-keyboard-mac/
I did accordingly but when I click my keyboard shortcut I get Finder menu not a currently selected file/folder menu.
This is an apple script used,
on run {input, parameters}
tell application "System Events" to set frontApp to name of first process whose frontmost is true
tell application "System Events"
tell application process frontApp
set _selection to value of attribute "AXFocusedUIElement"
tell _selection to perform action "AXShowMenu"
end tell
end tell
return input
end run
Spent hours trying to get this basic and obvious to every Windows user functionality to work, lost of time and very frustrating!
I think code is correct, maybe there is something specific on my computer that stops it from working as expected?
Please help :-)
Not sure i understood what is actually not working for you, but i had problem to reproduce the same script, once i wrote it in Automator.app i tried to press "play" button to see if the script was working and it was telling me something like "syntax error, can't get attribute AXFocusedUIElement of application process Automator" (from memory, not sure it's exactly what was written)
and struggled for a while as well untill i realised there was a pop window that i didn't see, saying me that "automator wants permission to control this computer using accessibility features (this thing in the system preference, security and privacy, privacy, accessibility), so i opened, there was a list of apps allowed to control my computer, i ticked Automator.app and after that it worked
Then every app that i was trying to do a right click was showing me the same pop up and i had to do the same for each one (safari, finder etc...)
And then it worked
Hope might help you!
Encountered same issue.
Allow 'Finder' to control computer at System Preferences>Security & Privacy>Privacy>Accessibility.
Worked for me
I'm trying to access information about the current status of a Mac app like I would with dbus on linux.
The app I'm trying to do this with is Spotify. I searched through the package contents and I found there was a Spotify.sdef file in the /Resources directory. I did some research on these "Script Definitions" and I think there's a way I can access the data described in the Spotify.sdef file (ie. the title and artist info). I may be completely wrong as I have zero experience with Cocoa development.
I'd be very grateful if someone could point me in the right direction on accessing the data I believe to be accessible from "Script Definition" file in an application's package contents. My final goal is to be able to see what song is currently playing in Spotify through a simple terminal command.
Have you seen Spotify's AppleScript docs? This small modification of the example should do what you're looking for:
#!/usr/bin/env osascript
set currentlyPlayingTrack to getCurrentlyPlayingTrack()
log currentlyPlayingTrack
on getCurrentlyPlayingTrack()
tell application "Spotify"
set currentArtist to artist of current track as string
set currentTrack to name of current track as string
return currentArtist & " - " & currentTrack
end tell
end getCurrentlyPlayingTrack
tell application "Finder" to say "this is a test"
tell aplication"finder"
activate
repeat 5 times
make new Finder window
end repeat
end tell
I am just learning different coding and know quite a bit about html, css, and javascript. I am completely new to apple script editor.
Since you're new to applescript I'll give you a basic tip to learn. Only tell an application to do something that it knows how to do. Each application knows how to do specific things and applescript knows how to do things by itself too.
I tell you this because the "say" command is an applescript command, not a Finder command. So there's no reason to tell the Finder to say anything. As you get more complex in your scripts you will find errors if you tell the wrong application to do something. As such you can run the say command by itself. Try this and it will work by itself...
say "this is a test"
The easiest way to know what each application understands is to look in the dictionaries. In Script Editor, under the file menu choose "open dictionary". You can choose any application but for this example open the Finder dictionary. You can search through it to find what the Finder knows how to do. You'll notice it doesn't have the "say" command thus you know not to tell the Finder to use the say command. You can type "say" into the search field and you'll see it doesn't return any results.
If you open the dictionary for "StandardAdditions" you'll find say in there. That's additional things applescript knows by itself.
Good luck.
The part tell aplication"finder" has two typos and is missing a space. It should be tell application "Finder"
The whole think should look like this which builds for me.
tell application "Finder" to say "this is a test"
tell application "Finder"
activate
repeat 5 times
make new Finder window
end repeat
end tell
I am developing an automated test for several Mac OSX apps with applescript. The app should do the following.
1.) Display dialog shows up, where the user can type in 1 or more app names he want to be tested for example (1.test.app, 2.autotest.app,....)
2.)depending on how many apps names he has typed in, the apps should start and close consecutively to check if they are working.
So for example if the user type in apptest1.app, apptest2.app, apptest3.app -> the first app starting should be apptest1.app and then close it, the next app should be apptest2.app start and close and so on.
thank you very much.
lg,
San
This should do the trick
tell application "Finder"
set thePath to path to applications folder
set theApps to get name of every file of thePath
set apps_to_test to choose from list (theApps) with multiple selections allowed
end tell
repeat with the_app in apps_to_test
tell application the_app
activate
quit saving no
end tell
end repeat
I'm using applescript to automate some browser activity. I have it tied to the speech recognition, so that I can make some custom voice commands.
One such command is "I wanna go home", which when heard, pulls up the relevant bus schedule on my browser. Given that the public transit system uses PHP and GET, the URL gets pretty long. Therefore, the keystroke myURL in the applescript takes a while to execute (something like 1-2 seconds). While I can live with losing 1-2 seconds, I'd really rather not.
With that in mind, is it possible to send these keystrokes faster? I believe I read somewhere that using key code is faster than using keystroke, but for the life of me, I can't figure out where I read that.
EDIT: My browser of choice is Google Chrome, which I couldn't find URL hooks for. This is why I had to resort to using keystrokes. Therefore, I'd prefer answers that work with Chrome over Safari
Another way to solve this is to put the text in the clipboard, then paste it. You can save the clipboard contents first and put it back afterward, so you don't lose what's already there. This method works in other situations when you want to enter a lot of text, not just for browser URLs like the other answers.
set clipboard_contents to (the clipboard)
set the clipboard to "Some long string that would take a while with the keystroke method"
tell application "System Events" to keystroke "v" using command down
delay 0.2 -- needed because otherwise the next command can run before the paste occurs
set the clipboard to clipboard_contents
I'm pretty sure you can script your browser to open the URL directly, instead of typing in the keystrokes (faking input events in AppleScript should be considered a last resort).
You can do this with the open location standard addition:
open location "http://google.com"
Open location is defined in Standard Additions and should not be enclosed in a tell statement.
open location "http://google.com"
If you want to target a specific browser you can use:
tell application "Safari"
if not (exists document 1) then reopen
set URL of document 1 to "http://google.com"
end tell
To target Chrome:
tell application "Google Chrome"
if not (exists window 1) then reopen
set URL of active tab of window 1 to "https://www.google.com/"
end tell