|
Post by addicted2boats on Dec 2, 2022 15:35:53 GMT
Dragging and dropping into a BASIC program doesn't work on a Mac. So I have found it very useful to use the clipboard commands. I can easily find a file using Finder (Mac app) and copy it to the clipboard. The BASIC program sees it on the clipboard and begins processing the file. The problem I have is trying to extract the PATH information for the filename on the clipboard. Obviously the Mac knows the PATH, because if I paste the file somewhere else the Mac knows where to go to retrieve the file. Is there a way to determine the PATH of a file that was copied to the clipboard, using BASIC or a Terminal command? I'm still looking for work-arounds, any help would be greatly appreciated.
If you really want to know why... I have a lot (6TB) of MP4s with subtitles in my video library. Before I add them to my media player hard drive I do extensive processing, here is a list: Compress the MP4s with Handbrake, which changes the format to .mkv and translates the internal subtitles. Extract the series episode numbers and names from a CSV file, and use them to rename the files appropriately. For some reason the subtitles don't work properly after being compressed by Handbrake, so I feed them into MKVtoolnix to extract the converted subtitles. I then feed the list of files back into MKVtoolnix to add the subtitle files back (which seems to fix them) and add the cover art files.
All this is REALLY time consuming, but I have most of it automated now using QB64! Now if I can only figure out where that file on the clipboard came from...
|
|
|
Post by bplus on Dec 2, 2022 22:25:58 GMT
If Mac is like Windows, find the last slash = LS in the pathed filename, the path is before that slash ie Path$ = Mid$(pathedFile$, 1, LS-1)
There was a _Reverse instr something that Fellippe added before v 2.0 that worked perfect for finding first char/str$ from right but I forgot the Command name and can't find it in Wiki yet. I will try a couple more things... it's not referenced from INSTR??
|
|
dbox
Junior Member
Posts: 89
|
Post by dbox on Dec 2, 2022 22:36:17 GMT
|
|
|
Post by bplus on Dec 2, 2022 22:37:12 GMT
That's it, just found it myself
|
|
|
Post by addicted2boats on Dec 3, 2022 19:56:40 GMT
I appreciate the help, unfortunately it doesn't work that way. I copy a file (filename.txt) to the clipboard on the Mac. I run a BASIC program that uses Name$ = _CLIPBOARD$. Name$ contains "filename.txt" without a PATH. Mac knows more information. If I open a text document and paste the clipboard it puts the filename in the document as text. But if I paste into Finder (Mac's version of File Explorer) it pastes the actual file, which implies it knows where the file is. I'm trying to find out how to get that PATH information. It might need to be done in a shell with a Terminal command, if it's even possible.
|
|
|
Post by bplus on Dec 3, 2022 23:04:06 GMT
addicted2boats we discussed 2 other methods of cross platform files access here: qb64.boards.net/thread/48/files-function-mimics-qb45QB64 has _CWD$ and ChDir you can make a little navigator/browser to obtain pathed filenames. The Direntry.h method gets lists of both folders and files. I was using it for Get_Filename.exe, I will find code and post.
|
|
|
Post by bplus on Dec 3, 2022 23:26:02 GMT
OK get_Filename a handy little GUI app I made up for gettin fully pathed filenames mainly. It's huge because it comes with GUI package and maybe looks nice: get_filename Readme.txt with brief instructions included in zip. Attachments:Get_Filename.zip (543.9 KB)
|
|
|
Post by addicted2boats on Dec 5, 2022 0:17:31 GMT
Thank you very much!!! I was hoping (but not hopeful) there was a more direct method to do this. Then I started thinking about what it would take to emulate a file browser in order to achieve what I needed. But you have already done all the work! I'm a little fuzzy tonight so I haven't executed it yet, but I'm sure it will get me there.
Since the files I am processing are in subfolders to my main media folder, I also considered selecting a file or folder, then using a shell command to have the Mac search for files or folders with that name, and getting the PATH from that. It wouldn't be a search of my entire hard drive, so not too intensive. But what you did was much more flexible.
Thank you again for all your help. I programmed my way around the missing _MOUSEWHEEL command using scroll boxes, but this PATH stuff was just an irritating thorn.
|
|
|
Post by bplus on Dec 5, 2022 17:00:39 GMT
Thank you is so nice! Thank you If anybody has questions or problems using the Filename Getter I'll be glad to answer or attempt to fix. Tip: I hate double clicking to select, it gives me twitchy finger muscles so selecting from List Box (Folders and Files) requires a left click to highlight the right line and a right click inside that same List Box to select the Highlighted Item. Because it is not Windows like I have a button underneath the Folder List Box to "select" to ChDir (Change Directorys). It is supposed to be cross platform but I only tested in Windows. I do use a forward slash for path + file for Linux users because Windows doesn't care but it might effect parsing out just the path name / folder. Just yesterday I wrote up this which I shouldn't need for my GUI but should work for parsing Path with the way I construct path names in get_Filename Function ParsePath$(PathedFilename$) Dim As Long t1, t2 t1 = _InStrRev(PathedFilename$, "\") t2 = _InStrRev(PathedFilename$, "/") If t1 > t2 Then ParsePath$ = Left$(PathedFilename$, t1 - 1) Else ParsePath$ = Left$(PathedFilename$, t2 - 1) End Function
Warning: I rewrote the above code in this forum editor to apply to the subject we are discussing but haven't run the code for typos, ect. Oh another helpful hint: If you make a list of pathed files in the _Clipboard, I most likely delimited them with Chr$(10) so if you print string it will come out as list. The GUI code in BM has an excellent String Splitter for parsing string of pathed filenames into an array for processing as you need: kill, copy, move, run... So you can run the _Clipboard string through the Splitter using Chr$(10) as demiter and get an array or PathedFilenames. I REDIM FileArray$(1 to 1) for Dynamic array (needed by splitter to resize as needed) using "1 to 1" so it is base 1 array so the ubound also equals the number of items I have in the array.
|
|
tonylazuto
New Member
Tony Lazuto says hello
Posts: 25
|
Post by tonylazuto on Dec 9, 2022 16:14:54 GMT
Sounds like you're running a Plex server. Good stuff. I have approximately 10TB myself. I don't process each file like you do, though.
|
|
|
Post by addicted2boats on Dec 22, 2022 16:33:10 GMT
Actually, never got around to Plex. Using hard drives and the last version of the WD TV media player. I like the stand-alone media player (I take it to hotels with me...) and have tried a bunch of different ones. They all seem to be written as though they don't expect you to have more than a few dozen movies. The indexes leave a lot to be desired. The WD TV player has a great index that can handle the 3,000+ videos on the drive. I did pull one sneaky trick though. I like the index to go from most recent to oldest movie. But most hard drive formats won't go back beyond 1956 (the first commercial hard drive manufacturing date). So I have to store my movies on NTFS drives. It is the only way I can keep the "created" and "last modified" dates that are older than 1956.
|
|
|
Post by addicted2boats on Dec 27, 2022 15:51:41 GMT
OKAY!!!!! I finally found the appropriate method. As I often find on the Mac, there was a simple solution that wasn't well documented. I searched and searched and finally stumbled on it. It fits in with the "standard" way of doing things on a Mac, but seems to get overlooked by just about everyone. Anyway, I'm rambling.
In Finder (the Mac equivalent of File Explorer) if you select files or folders, then right-click on them, you can copy them to the clipboard. Simple and straight forward. But it doesn't copy the Path information. There are 3 simple ways to accomplish this. A) Right-click on the files/folders. Instead of clicking on the "Copy" entry, hold down the [Option] key. "Copy" becomes "Copy as Pathnames". That's it! Dead simple. It copies the entire path and filename to the clipboard. B) If you are keyboard centric, use [Command]+[Option]+[C]. C) If you are mouse-centric like me, you don't have to press the [Option] key if you add a "Copy Path" option to your right-click menu. It requires Automator, but is dead simple to do: 1) Start Automator from your Applications folder. If you see a big, relatively empty window (for selecting existing workflows) click on the [Done] button to close it. 2) On the pulldown menu select File>New. 3) You should be at the main Automator window, with a pop-up asking you to "Choose a type for your document". 4) Double-click on "Service". 5) At the top select "Service receives selected files or folders" and "in Finder.app". 6) In the far left pane select "Utilities". 7) In the middle pane double-click on "Copy to Clipboard", you'll see it show up in the right pane. 8) Select File>Save from the pulldown menu and choose a name (Copy Path).
That's it! Now when you right click on files/folders you will see Copy Path in the dialog box. By the way, if it gets pushed into a submenu called "Services", it is because Mac only allows 4 services in the menu before it creates the submenu. You can fix this by deleting unused services, or by running a command to increase the number of allowed services. I ran "defaults write -g NSServicesMinimumItemCountForContextSubmenu -int 999" in Terminal (without the quotes).
Also, you will have to relaunch Finder before these services will show up in the context menu. Use the Terminal command "killall Finder" if you wish.
So I can't drag and drop on a Mac, but I can start my Basic program, then use Finder to select and copy the folder(s)/filename(s) with complete Path to the clipboard, which works really well. I hope other Mac users will find this as useful as me.
|
|
|
Post by addicted2boats on Jan 12, 2023 14:24:59 GMT
Just when I thought it was safe to go back into the water... I hit a new snag with _CLIPBOARD$ on the Mac. It doesn't return the data from the clipboard properly when there are file paths involved. Here is a simple program:
_CLIPBOARD$ = "" PRINT "Copy the files to the clipboard." DO UNTIL _CLIPBOARD$ <> "" LOOP CLS PRINT _CLIPBOARD$ SLEEP SYSTEM
If I select multiple files/folders in Finder, _CLIPBOARD$ returns all the titles (without the Paths). If I select multiple files/folders with their Paths as described above, _CLIPBOARD$ only returns the first title. I know it contains all of them because I can paste to a blank document and they are all there with their paths.
For example, if I select the following files using Copy:
/Applications/QB64/Programs/File1.rtf /Applications/QB64/Programs/File2.txt /Applications/QB64/Programs/File3.pdf
_CLIPBOARD$ returns: File1.rtf File2.txt File3.pdf
If I select them using Copy Items As Pathnames, _CLIPBOARD$ returns: /Applications/QB64/Programs/File1.rtf
But if I paste the clipboard into a blank document I get: /Applications/QB64/Programs/File1.rtf /Applications/QB64/Programs/File2.txt /Applications/QB64/Programs/File3.pdf
So I know the information is there, I just can't get to it. Any Ideas?
|
|
tonylazuto
New Member
Tony Lazuto says hello
Posts: 25
|
Post by tonylazuto on Jan 12, 2023 16:38:51 GMT
The last instance you mentioned where you only get the first item in a list of items copied; it sounds like it has something to do with null characters. Try pasting your list of filenames into something like Notepad++ with the symbols turned on and see what characters are terminating each line.
|
|
|
Post by addicted2boats on Jan 12, 2023 19:05:12 GMT
I agree there is probably some character in the clipboard that is creating trouble for QB64. I'm on a Mac, not Windows, so no Notepad+++. I tried pasting into an RTF and into a TXT using TextEdit. As expected MacOS added formatting commands to the RTF, but not the TXT. In both cases it appeared the only terminating character at the end of the line was ASCII 10 (Linefeed). The very last line had no terminating character. I ran a BASIC program that opened the RTF and TXT files for binary input, and changed any non-printing characters into ASCII numbers in the output. I'm not sure how QB64 retrieves the data for the _CLIPBOARD$ function, but my guess would be that is where the problem lies. I don't know anything about memory commands but wonder if the function reads a register and isn't reading the whole thing.
The following are the resulting RTF and TXT file contents. Please note that the "∞" character on each side of the ASCII value was placed there by my program to distinguish say "10" from CHR$(10).
Actual copied files: /Applications/QB64/source /Applications/QB64/Terminal Command Line reference /Applications/QB64/_BASIC Screen grid - 80x50 Blank.docx /Applications/QB64/_Ideas for QB64.rtf
RTF file output: {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf610∞10∞ \cocoascreenfonts1{\fonttbl\f0\fswiss\fcharset0 Helvetica;}∞10∞ {\colortbl;\red255\green255\blue255;}∞10∞ {\*\expandedcolortbl;;}∞10∞ {\info∞10∞ {\author Scott Smith}}\paperw15840\paperh12240\margl1008\margr1008\margb1008\vieww31820\viewh16820\viewkind1\viewscale200∞10∞ \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0∞10∞ ∞10∞ \f0\fs24 \cf0 /Applications/QB64/source\∞10∞ /Applications/QB64/Terminal Command Line reference\∞10∞ /Applications/QB64/_BASIC Screen grid - 80x50 Blank.docx\∞10∞ /Applications/QB64/_Ideas for QB64.rtf}
TXT file output: /Applications/QB64/source∞10∞ /Applications/QB64/Terminal Command Line reference∞10∞ /Applications/QB64/_BASIC Screen grid - 80x50 Blank.docx∞10∞ /Applications/QB64/_Ideas for QB64.rtf
|
|