play a stream in iTunes without adding it to the library / playlist - streaming

I am controlling iTunes via AppleScript and I am playing streams from an HTTP server. The code I'm using looks like this:
tell application "iTunes"
open location "your_url_here"
play
end tell
It works fine, but I would like to avoid those URLs to show up in the iTunes library or any playlist afterwards. Is there a trick to achieve that?

Have you considered using QuickTimePlayer to play the stream instead?
tell application "QuickTime Player"
open URL "http://www.a-1radio.com/listen.pls"
end tell
It should open all the iTunes formats, it comes as a default on OsX, it is more "minimal", won't save tracks.
(I know you specified you want to use iTunes so this might not be a solution, but being preinstalled software it was worth a try)
EDIT To have it hidden, this seems to work:
tell application "QuickTime Player"
-- don't use launch or activate
-- on my mac with launch I see a flicker of the window
set numberOfWindows to (count windows)
repeat with i from 1 to numberOfWindows
close front window
end repeat
end tell
-- may add some delay here if it still flickers the window
-- delay 1
tell application "QuickTime Player"
open URL "http://www.a-1radio.com/listen.pls"
set visible of every window to false
end tell
tell application "System Events"
set visible of process "QuickTime Player" to false
end tell
-- must be called after the open URL command or won't work (no idea why)
To close the stream either quit or close windows (just close if you plan to reopen):
tell application "QuickTime Player"
-- here you can either:
-- close all (will leave app open and hidden)
set numberOfWindows to (count windows)
repeat with i from 1 to numberOfWindows
close front window
end repeat
-- or:
quit -- or just quit (will close app so will need to hide again next time)
end tell
If you hide it before opening the url, it doesn't work (no idea why). Of course the window, even if invisible, is still open so if someone clicks on the dock icon it will show all the open windows.
If you don't want to stop previous streams remove the first repeat -- end repeat part at the top, but leave the set numberOfWindows to (count windows) that is useless but activates the app without needing a activate/launch command

Related

Issues with irrecord lirc function

I am trying to setup a remote to work with an IR reciever that I recently purchased using my raspberry pi, I've installed LIRC according to the following tutorial
https://www.digikey.com/en/maker/blogs/2021/how-to-send-and-receive-ir-signals-with-a-raspberry-pi
now the problem arises when I try and record to setup a specific remote, it saves all the values as 0x0,
here is the console output when setting up the remote that doesn't work
Running as regular user pi
Using driver default on device /dev/lirc0
irrecord: could not open logfile "/home/pi/.cache/irrecord.log"
irrecord: Permission denied
irrecord - application for recording IR-codes for usage with lirc
Copyright (C) 1998,1999 Christoph Bartelmus(lirc#bartelmus.de)
This program will record the signals from your remote control
and create a config file for lircd.
A proper config file for lircd is maybe the most vital part of this
package, so you should invest some time to create a working config
file. Although I put a good deal of effort in this program it is often
not possible to automatically recognize all features of a remote
control. Often short-comings of the receiver hardware make it nearly
impossible. If you have problems to create a config file READ THE
DOCUMENTATION at https://sf.net/p/lirc-remotes/wiki
If there already is a remote control of the same brand available at
http://sf.net/p/lirc-remotes you might want to try using such a
remote as a template. The config files already contains all
parameters of the protocol used by remotes of a certain brand and
knowing these parameters makes the job of this program much
easier. There are also template files for the most common protocols
available. Templates can be downloaded using irdb-get(1). You use a
template file by providing the path of the file as a command line
parameter.
Please take the time to finish the file as described in
https://sourceforge.net/p/lirc-remotes/wiki/Checklist/ an send it
to <lirc#bartelmus.de> so it can be made available to others.
Press RETURN to continue.
Checking for ambient light creating too much disturbances.
Please don't press any buttons, just wait a few seconds...
No significant noise (received 0 bytes)
Enter name of remote (only ascii, no spaces) :notworking
Using notworking.lircd.conf as output filename
Now start pressing buttons on your remote control.
It is very important that you press many different buttons randomly
and hold them down for approximately one second. Each button should
generate at least one dot but never more than ten dots of output.
Don't stop pressing buttons until two lines of dots (2x80) have
been generated.
Press RETURN now to start recording.
................................................................................
Got gap (108172 us)}
Please keep on pressing buttons like described above.
.....................................................................................................................................................Cannot find any gap, using an arbitrary 50 ms one. If you have a
regular remote for e. g., a TV or such this is probably a point
where you hit control-C. However, technical hardware like air
condition gear often works without any gap. If you think it's
reasonable that your remote lacks gap you can proceed.
Press RETURN to continue.
Please enter the name for the next button (press <ENTER> to finish recording)
KEY_UP
Now hold down button "KEY_UP".
Please enter the name for the next button (press <ENTER> to finish recording)
KEY_DOWN
Now hold down button "KEY_DOWN".
Please enter the name for the next button (press <ENTER> to finish recording)
KEY_LEFT
Now hold down button "KEY_LEFT".
Please enter the name for the next button (press <ENTER> to finish recording)
KEY_RIGHT
Now hold down button "KEY_RIGHT".
Please enter the name for the next button (press <ENTER> to finish recording)
KEY_OK
Now hold down button "KEY_OK".
Please enter the name for the next button (press <ENTER> to finish recording)
Checking for toggle bit mask.
Please press an arbitrary button repeatedly as fast as possible.
Make sure you keep pressing the SAME button and that you DON'T HOLD
the button down!.
If you can't see any dots appear, wait a bit between button presses.
Press RETURN to continue.
...Cannot find any toggle mask.
Successfully written config file notworking.lircd.conf
Here is what the config file that's generated looks like
Now, if I setup another remote I have laying around I get a correct config file
Here is a picture of the two remotes sitting side by side, the remote on the left is the one that is not working
I've tried using this tutorial too to no avail
https://www.raspberrypi.org/forums/viewtopic.php?t=235256
does anyone know what's going on here?

Applescript drag and drop doesn't work

I am new to Applescript, and wrote a script to securely wipe files, which brings up a file-selection dialog and confirmation, then wipes the file. However, when I tried to add drag and drop functionality, it doesn't work like everyone says it should. The icon never highlights (indicating drag and drop is working), and Finder just copies the file to the app's folder instead of dragging onto the app!
Here is the original script, which works fine (saved as "Wipe File.app"):
on run
set the_file to choose file with prompt "Select the file to wipe:"
wipe_file(the_file)
end run
to wipe_file(file_to_wipe)
set file_to_wipe to POSIX path of file_to_wipe
set ok_to_wipe to display dialog "Are you sure you want to wipe \"" & file_to_wipe & "\"?" buttons {"Cancel", "OK"} default button "Cancel"
set ok_to_wipe to button returned of ok_to_wipe
if (ok_to_wipe = "OK") then
tell application "Terminal"
activate
do script "set prompt='';cls;srm -v \"" & file_to_wipe & "\""
delay 3
close front window
set still_active to count windows
if still_active = 0 then
quit
end if
end tell
end if
end wipe_file
Then I added the following to the top. Running the script still works with the file-selection dialog, but the system never allows drag and drop!
on open the_files
repeat with the_file in the_files
wipe_file(the_file)
end repeat
end open
Everywhere I looked (Google, stack overflow) all say this approach should work, but it doesn't. I even tried removing the on run... block, leaving just on open..., but then the script does nothing at all.
EDIT
If I create a new script with the content above, and save it as an app, then copy it to the Applications folder, and paste a custom icon onto it, drag and drop works. However, the old script, which originally didn't have "on open" support, still doesn't work even after "on open" support was added to the script. So now I'm thinking that Apple must set some special attribute to indicate a script supports drag and drop, and for some reason (because it didn't have it when I first saved?) Apple didn't set that attribute for my file. Looking at Get Info and Show Package Contents for both apps, there are some strange differences:
The newly-created (working) app is only 693 KB, but the old (supposedly identical, but broken) one is 9.4 MB!
Inside the Contents/MacOS folder, the new (working) app has a file called "droplet", whereas the old one (broken) one has a file called "applet".
The first one is bizarre, and made me think of some sort of file corruption, but the second one is clearly the magic setting Apple uses for drag and drop. I verified that if I remove the "on open" block from the working script, and save it, Apple does not update the script icon to remove the "drop" arrow, and you can still drag and drop files onto it, but nothing happens.
So it seems that Apple decides whether a script supports drag and drop or not the first time it saves the script, and after that you get the wrong results unless save a brand new script!
You do not need to call Terminal and open window. The ‘do shell script’ opens already a shell session, in background, not visible in Terminal. You must just use it inside a 'try/end try' block to avoid script stops in case of error (like no authorization for the files !)
Also you are using ‘srm’ with option v (verbose). This option is used to display what is being done, but you do not see it because you are closing the window.
The possible issue of your script could also be when your file path contains special characters which must be escaped in shell. To avoid this, use ‘quoted form of ‘.
Script bellow is tested OK :
on run
set the_file to choose file with prompt "Select the file to wipe:"
wipe_file(the_file)
end run
on open the_files
repeat with the_file in the_files
wipe_file(the_file)
end repeat
end open
to wipe_file(file_to_wipe)
set file_to_wipe to POSIX path of file_to_wipe
set ok_to_wipe to display dialog "Are you sure you want to wipe \"" & file_to_wipe & "\"?" buttons {"Cancel", "OK"} default button "Cancel"
if (button returned of ok_to_wipe = "OK") then
try
do shell script "srm " & quoted form of (file_to_wipe)
end try
end if
end wipe_file

Running Apple Script on hidden safari window

I am running apple script.
My problem is that i am opening a safari window using apple script.
After that I am hiding it using script
tell application "System Events" to tell process "Safari" to set visible to false
Now I want that my leftover script should run on that safari window which is hidden, but when i hide safari window then the focus to the safari is lost and the script starts running on the application that has focus instead of safari window.
Can we do this? Please tell the solution if we can.Any help is appreciated.
Thanks.
What are you trying to do with the window? If I hide Safari with an open window, I can still access the window using the normal tell block, like
tell application "Safari"
set bounds of window 1 to {111, 222, 777, 666}
end tell
with no problem. But perhaps you are using System Events, which may not be necessary (and possibly bad practice) but it depends on what you're trying to do. Check Safari's dictionary, and post example code.
try this
tell application "System Events" to set visible of process "Safari" to false
This worked for me:
tell application "Safari"
activate
delay 1
tell application "System Events" to set visible of process "Safari" to false

iOS simulator options changes

When I open any song site through simulator of iPhone or iPad say mp3skull.com . and when i click on option download It gives me the Alertview option to COPY and OPEN . IS there any way I can give one more option in this .say open copy download. for more clarity shown in page :
1st off: I no not think that adding a specific item there is possbile.
Now assuming you actually want to add a "Download" button, consider this:
Opening a file by default means you have to download the file first
"Download" on a PC/Mac just puts the file into a "known" folder where you can open it with any program later while "open" puts it into a (possibly) random temp folder and then runs the default program
Due to the nature of safari in iOS a "Download" button would be more like "Store in Safari for later"
Open in safari is -> Download, Store, Ask user what app he wants to use to open the file type.
So considering the above points I do not see how a "Download" button would function. If you have some more details what you want your button to do, maybe there is an alternative that will work for you.

What determines the monitor my app runs on?

I am using Windows, and I have two monitors.
Some applications will always start on my primary monitor, no matter where they were when I closed them.
Others will always start on the secondary monitor, no matter where they were when I closed them.
Is there a registry setting buried somewhere, which I can manipulate to control which monitor applications launch into by default?
#rp: I have Ultramon, and I agree that it is indispensable, to the point that Microsoft should buy it and incorporate it into their OS. But as you said, it doesn't let you control the default monitor a program launches into.
Here's what I've found. If you want an app to open on your secondary monitor by default do the following:
1. Open the application.
2. Re-size the window so that it is not maximized or minimized.
3. Move the window to the monitor you want it to open on by default.
4. Close the application. Do not re-size prior to closing.
5. Open the application.
It should open on the monitor you just moved it to and closed it on.
6. Maximize the window.
The application will now open on this monitor by default. If you want to change it to another monitor, just follow steps 1-6 again.
Correctly written Windows apps that want to save their location from run to run will save the results of GetWindowPlacement() before shutting down, then use SetWindowPlacement() on startup to restore their position.
Frequently, apps will store the results of GetWindowPlacement() in the registry as a REG_BINARY for easy use.
The WINDOWPLACEMENTroute has many advantages over other methods:
Handles the case where the screen resolution changed since the last run: SetWindowPlacement() will automatically ensure that the window is not entirely offscreen
Saves the state (minimized/maximized) but also saves the restored (normal) size and position
Handles desktop metrics correctly, compensating for the taskbar position, etc. (i.e. uses "workspace coordinates" instead of "screen coordinates" -- techniques that rely on saving screen coordinates may suffer from the "walking windows" problem where a window will always appear a little lower each time if the user has a toolbar at the top of the screen).
Finally, programs that handle window restoration properly will take into account the nCmdShow parameter passed in from the shell. This parameter is set in the shortcut that launches the application (Normal, Minimized, Maximize):
if(nCmdShow != SW_SHOWNORMAL)
placement.showCmd = nCmdShow; //allow shortcut to override
For non-Win32 applications, it's important to be sure that the method you're using to save/restore window position eventually uses the same underlying call, otherwise (like Java Swing's setBounds()/getBounds() problem) you'll end up writing a lot of extra code to re-implement functionality that's already there in the WINDOWPLACEMENT functions.
It's not exactly the answer to this question but I dealt with this problem with the Shift + Win + [left,right] arrow keys shortcut. You can move the currently active window to another monitor with it.
Get UltraMon. Quickly.
http://realtimesoft.com/ultramon/
It doesn't let you specify what monitor an app starts on, but it lets you move an app to the another monitor, and keep its aspect ratio intact, with one mouse click. It is a very handy utility.
Most programs will start where you last left them. So if you have two monitors at work, but only one at home, it's possible to start you laptop at home and not see the apps running on the other monitor (which now isn't there). UltrMon also lets you move those orphan apps back to the main screen quickly and easily.
I'm fairly sure the primary monitor is the default. If the app was coded decently, when it's closed, it'll remember where it was last at and will reopen there, but -- as you've noticed -- it isn't a default behavior.
EDIT: The way I usually do it is to have the location stored in the app's settings. On load, if there is no value for them, it defaults to the center of the screen. On closing of the form, it records its position. That way, whenever it opens, it's where it was last. I don't know of a simple way to tell it to launch onto the second monitor the first time automatically, however.
-- Kevin Fairchild
Important note: If you remember the position of your application and shutdown and then start up again at that position, keep in mind that the user's monitor configuration may have changed while your application was closed.
Laptop users, for example, frequently change their display configuration. When docked there may be a 2nd monitor that disappears when undocked. If the user closes an application that was running on the 2nd monitor and the re-opens the application when the monitor is disconnected, restoring the window to the previous coordinates will leave it completely off-screen.
To figure out how big the display really is, check out GetSystemMetrics.
So I had this issue with Adobe Reader 9.0. Somehow the program forgot to open on my right monitor and was consistently opening on my left monitor. Most programs allow you to drag it over, maximize the screen, and then close it out and it will remember. Well, with Adobe, I had to drag it over and then close it before maximizing it, in order for Windows to remember which screen to open it in next time. Once you set it to the correct monitor, then you can maximize it. I think this is stupid, since almost all windows programs remember it automatically without try to rig a way for XP to remember.
So I agree there are some apps that you can configured to open on one screen by maximizing or right clicking and moving/sizing screen, then close and reopen. However, there are others that will only open on the main screen.
What I've done to resolve: set the monitor you prefer stubborn apps to open on, as monitor 1 and the your other monitor as 2, then change your monitor 2 to be the primary - so your desktop settings and start bar remain. Hope this helps.
Do not hold me to this but I am pretty sure it depends on the application it self. I know many always open on the main monitor, some will reopen to the same monitor they were previously run in, and some you can set. I know for example I have shortcuts to open command windows to particular directories, and each has an option in their properties to the location to open the window in. While Outlook just remembers and opens in the last screen it was open in. Then other apps open in what ever window the current focus is in.
So I am not sure there is a way to tell every program where to open. Hope that helps some.
I've noticed that if I put a shortcut on my desktop on one screen the launched application may appear on that screen (if that app doesn't reposition itself).
This also applies to running things from Windows Explorer - if Explorer is on one screen the launched application will pick that monitor to use.
Again - I think this is when the launching application specifies the default (windows managed) position. Most applications seem to override this default behavior in some way.
A simple window created like so will do this:
hWnd = CreateWindow(windowClass, windowTitle, WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, SW_SHOW, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);
Right click the shortcut and select properties.
Make sure you are on the "Shortcut" Tab.
Select the RUN drop down box and change it to Maximized.
This may assist in launching the program in full screen on the primary monitor.