Opening an image using 'system' or 'exec' - ruby

My goal is to open image files in a default image viewer (Windows 10 Photos app), and close them per user input. My file path contains backslashes, not standard slashes, although replacing them doesn't seem to change the results I mention below.
I tried the following:
Kernel.system('full_path_to_image')
or the same thing using exec instead, but it simply returns a format error Errno::ENOEXEC. Manually entering the file path in the command interpreter works even if the interpreter is opened via:
Kernel.system('cmd')
I tried to avoid the shell by using a multi-argument version of system, but I could not.
Is it possible to do what I want to?

According to this answer, this should work on windows.
system("start #{path_to_image}")

Related

Set Extended Attributes with AppleScript Objc

So I am looking for a way to set Mac specific extended attributes (specifically kMDItemWhereFroms) for a file (Image File, Jpg) using AppleScript or AppleScript-Objc.
There is a command line tool that will do this xattr -w kMDItemWhereFroms . The problem is that on the several machines that I have access to (10.12, 10.13, and 10.14) when you run this command as a do shell script from within an AppleScript it does not work, the metadata is not added to the file. If I set Script Debugger to debug mode, and go through the script step by step it will actually set the metadata, but since that is not the way I am running the script, it is more of an interesting fluke than anything else. I have tried running the command with both "com.apple.metadata:" included and not included with the shell script and that makes no difference.
I have tried running my script through SD, Script Editor and osascript, and they all fail to update the metadata. So I am thinking that this tool might be broken when called from an AppleScript.
I found setxattr but that looks like it only applies to C.
So my questions are
1. Is there a way to set the extended attributes of a file on MacOS using Aobjc? if not then
2. Is there a way to get setxattr to work with either version of AppleScript? Probably not so
3. Any ideas how I might be able to get the command line tool xattr -w kMDItemWhereFroms to work when using scripting?
This is more of an annoyance for me, I am just being stubborn with wanting the source of the file to show up in the "Where From" data in the Get Info window from the Finder. I already am setting some metadata for the file using exiftool. So it is more of an interesting problem for me, than a critical problem that I must try and solve now. Thanks!

Why does nothing changed to open a program in windows while using the assoc command to alter the specific extension to another different?

I use the windows 10 pro version and open the command prompt as the administrator to run the windows commands in my laptop. Using the assoc command to change the file extension file to another different (e.g. assoc .jpg=txtfile), I find nothing changed after running it and still that jpeg file opens with the regular program instead of notepad. In addition I can see the only change in by typing just the assoc and running it when a list of extensions belonging to different programs appears. Fo instance I have changed the .jpg file to txt file that it shows only as '.jpg=txtfile" in the list but tyat is still opened in jpeg program not notpad? Is anyone here to help me with clearly. Thanks
You need to use ftype as well. I have a link saved to MS docs that says it is up-to-date till Win8: https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc771394(v=ws.11).
Maybe nothing has changed in Win10, but you get the idea from the above and can Google it for Win10.

Unable to append redirected output files in windows

I am using a log file which is logged in using redirected output method and not the usual logging functions or subroutines.
I need to open the file in appending mode in order to truncate the same every hour.
In linux, i can successfully open the file in append mode and use truncate() function.
But in windows, the file doesnt open in append mode or open using the perl file operators.
Running with if statement gives me false value condition on appending the files, in windows.
the same code and logic works differently on linux and windows.
tried the >>,+>,> file operators in perl but none works in windows.
What can be the reason for the same and solution for this?
No reason appending to a file wouldn't work in Windows. But this nugget in perlport might be what you need to know:
truncate
If a FILEHANDLE is supplied, it must be writable and opened in append mode (i.e., use open(FH, '>>filename') or sysopen(FH,...,O_APPEND|O_RDWR). If a filename is supplied, it should not be held open elsewhere. (Win32)

Why does one code execute from one folder but not the other?

I was just curious as to why with Windows O/S a simple Ruby file that prints one line to the command prompt can execute correctly from one path, but not the other.
Currently, I have said file in C:\Ruby193\test\lib saved inside the lib folder. When I go to the command prompt and set the path to C:\Ruby193\test\lib, I'd expect to see the code string be printed to the command prompt. However, nothing but an empty line is produced, and if I go up the path and set it to C:\Ruby193\test and execute the ruby file from there, it works just fine.
Does anyone have a sound explanation as to why it works that way? Would this also be the same case for a MAC O/S as well?

How to open a file from the command line with a specified program?

I would like to open a PDF in Photoshop from the command line. My current issue right now is that the default application for opening PDFs is Adobe Acrobat. I'm wondering if there is any parameter I can pass to specify which program to use when opening a file.
In other words, I want to emulate the option of "Open-with" when you right-click a file to open it with the non-default application, but from the command line.
I do not want to change the default application for PDFs to be Photoshop.
Any ideas?
All you need to is provide the filename as a command line argument:
photoshop <path to file>
(<path to file> needs to be quoted if it contains spaces)
For example:
photoshop "C:\Users\csterling\Documents\some document.pdf"
If the directory containing photoshop.exe isn't in your Path environment variable, you'll need to provide the full path:
"C:\Program Files\Adobe\Photoshop\photoshop" "C:\Users\csterling\Documents\some document.pdf"
This isn't a feature of the command prompt, it's a feature of the executable, i.e. photoshop.exe has to be programmed to accept a file to open as a command line argument. Fortunately, it is, as are the majority of Windows applications that operate on files.
In case you want this to work with relative path in PowerShell, here is the script:
function photo
{
$the_filename=resolve-path $args[0]
photoshop $the_filename
}
Then you can just type:
cd C:\Users\csterling\Documents
photo mypic.jpg
You can do it by using the start command:
start <program-name> <file-path>
In your case, you would have to do something like this:
start photoshop D:\open.pdf
Unfortunately, the current version of Photoshop doesn't support this operation out of the box. You can open the program: start "path_to_photoshop.exe", but there is no way to pass it a file to open. If you really want to do it, you will need to get something like this: https://www.eulanda.eu/en/access-photoshop-api-via-powershell-script. Sorry, I wish I had a better answer, especially since I wanted to be able to do this for a program I was working on.

Resources