I created a droplet that is supposed to pass a file (which is being dropped on the droplet) to a website in safari in a file dialog.
I managed most of it... but the file path I get through "theDroppedItems" starts with file:// and it also includes characters like %20 and ~ and more weird characters.
Is there a way to convert this to a "real path" that safari accepts?
solved:
set inx to item 1 of theDroppedItem
set iny to POSIX path of inx
Related
I have a remote server I have read permission (in Windows I labeled it as my X: drive)
The correct path to a file I need to access is:
"X://some dir/some file"
The file that holds the Macro that is running exists in the C: drive. The code below checks to see if the path exists
If dir("X://some folder/some file", vbDirectory) = "" Then
Debug.Print "dir does not exist"
End If
Running that above enters the branch telling me the file does not exist. My questions are:
Do I have to put the name of the drive shorcut? (eg X: or can I put //: instead?)
How can I debug in Excel if I'm even allowed to enter the drive?
First, use backslashes for Windows paths. Second, don't use double backslashes when referring to a mapped drive. (Labelling the drive is meaningless to VBA.) eg:
X:\some folder\some file
If you didn't actually create a mapped drive, you will need to use the UNC or IP (and then you do use the double backslash) . EG:
\\remotehost\path\to\somefolder\somefile.txt
or
\\127.0.0.1\path\to\some folder\some file.txt
I think Tim is correct.
How can I debug in Excel if I'm even allowed to enter the drive?
If you RECORD macro opening a file in your X drive. You will see all the code that you need to put your original code working ;) . Every VBA coder do that kind of tricks.
I want to find files at a given location whose content matches a given string. For example, there are a lot of files inside the desktop folder (or anywhere), like *.pdf, *.rtf, *.doc, *.txt, *.html and so on.
The user will be prompted to enter a string thistext and select the location /Users/UserName/Desktop. I want to get a list of the files from this location whose content contains thistext.
I found a command utility mdfind, but it returns the files whose name contains thistext as well. I don't want these files in the result list; I only want files whose content is thistext. I've used grep, but it's not working properly for me. Is there a way to customize grep or mdfind command to work for me?
Or if there is any AppleScript script available for performing such task?
I think there are some syntax errors in the above answer.
I just tested this in AppleScript, and it works for me in Yosemite 10.10.5:
set textToSearchFor to "YourTextHere"
set searchDir to "~/Documents/Test/"
set cmdStr to "mdfind 'kMDItemTextContent == \"*" & textToSearchFor & "*\"cd' -onlyin " & searchDir
set lstFiles to (do shell script cmdStr)
log lstFiles
Result:
(*/Users/UserName/Documents/Test/PDF_Log.txt*)
You can specify a query that only examines each file's text content, like so:
mdfind -onlyin ~/Desktop 'kMDItemTextContent == *thistext* cdw'
The cdw at the end of the query string means the comparison should ignore case, diacritics, and width (which is mostly relevant for text with Asian characters).
Also, if you're doing this from an app, you shouldn't invoke the mdfind command as a subprocess. You should use the NSMetadataQuery class to do it within your app.
Using Windows, I've experienced a slight annoyance when using __FILE__ to get the current location of a file or the absolute path of another file with
File.expand_path("lib/other", File.dirname(__FILE__))
This doesn't work though if the folder has characters like äöüè and similar. This get's especially annoying if the windows username of a client contains such a character and my script necessarily lives inside the %appdata% folder.
To demonstrate my problem, C:\äüé\test.rb contains only
puts __FILE__
Running it:
> ruby C:\äüé\test.rb
C:/"?'/test.rb
Is there a reliable way to get the current file path?
How to (easily) get current file path in Sublime Text 3
I don't often use ST console (I used it only once to install package manager), but I suppose it could be good way to :
get current file path like some kind pwd command.
But it doesn't work.
Does anyone know an easy way to get current file path?
to clipboard : better not a strict objective in the answer
not necessary by ST command, maybe package?
Right click somewhere in the file (not on the title tab) --> Copy file path
If you don't want to use the mouse, you could set up a keyboard shortcut as explained here https://superuser.com/questions/636057/how-to-set-shortcut-for-copy-file-path-in-sublime-text-3
To easily copy the current file path, add the following to Key Bindings - User:
{ "keys": ["ctrl+alt+c"], "command": "copy_path" },
Source
Key Bindings - User can be opened via the command palette (command + p on OSX)
Easy to understand using image. On Right Click you will get this.
Transcribed code in image for convenience:
import sublime, sublime_plugin, os
class CopyFilenameCommand(sublime_plugin.TextCommand):
def run(self, edit):
if len(self.view.file_name()) > 0:
filename = os.path.split(self.view.file_name())[1]
sublime.set_clipboard(filename)
sublime.status_message("Copied file name: %s" % filename)
def is_enabled(self):
return self.view.file_name()... # can't see
Mac OS X - Sublime Text 3
Right click > Copy File Path
A lot of these answers involve touching the mouse. Here's how to do get the path without any mouse clicks using SideBarEnhancements
Install SideBarEnhancements using PackageControl.
Click super + shift + P to open the command palette
In the command palette begin typing path until you see File: Copy Path
Select File: Copy Path
Now the path to file you are working in is copied into your clipboard.
There is a Sublime Package which gives your current file location inside a status bar. I just cloned them directly to my /sublime-text-3/Packages folder.
git clone git#github.com:shagabutdinov/sublime-shell-status.git ShellStatus;
git clone git#github.com:shagabutdinov/sublime-status-message.git StatusMessage;
You have to check/read the description on GitHub. Even it is listed in package control it would not install properly for me. You can actually edit the shell output as you want. If you have the right skills with python/shell.
Looks like this (Material Theme)
If you're like me and always click on items in the sidebar just to realize that copying the path only works when clicking in the editor area, have a look at the SideBarEnhancements package. It has a huge bunch of options to copy file paths in a variety of different ways.
Installation is available via Package Control (despite the webpage only mentions installation via manual download).
Note: The package “sends basic, anonymous statistics”. The webpage explains how to opt out from that.
Go to this link. The code in the link is given by robertcollier4.
Create a file named CpoyFileName.py or whatever you like with .py extension.
Save the file in Sublime Text 3\Packages\User folder. Then paste the above given key bindings in your Preferences: Key Bindings file.
Now, you can use the specified key bindings to copy just filename or total (absolute) filepath.
Please note that the filename or filepath do contain file extension.
Fastest Solution ( No Packages Needed + Comprehensive ):
Folder Path:
Folder in "Sidebar"
Right Click
"Find In Folder"
"Where" field contains everything you need
File Path:
File in current "Tab"
Right Click
"Copy File Path"
I am trying to add a Windows Context Menu item that will let me right click a file in Windows Explorer and click a button Open in Dev Server.
This will then pass the file path of the selected file to a Windows .bat file.
In my .bat file openLocalHostWebBrowser.bat so far I have this code below which wehn ran opens a new tab in my web browser with the supplied URL.
#echo off
start "webpage name" "http://someurl.com/"
So I need help. I know how to add the context menu in Windows Explorer that will run my openLocalHostWebBrowser.bat file when clicked on.
What I need help with is taking that file path that is passed and changing it by removing part of the front of it and prepending my localhost or any URL for that matter, perhaps another one for a production server.
So if the file path passed to my .bat file is like this...
E:\Server\htdocs\labs\php\testProject\test.php
then I need to somehow turn it into this...
http://localhost/labs/php/testProject/test.php
The E:\Server\htdocs\ should be replaced with http://localhost/
I believe your requirement is fixed (E:\Server\htdocs\ should be replaced with http://localhost/). If so, below may help you.
#echo off
set input=%1
Echo.Input was - %input%
set converted=%input:E:\server\htdocs\=http://localhost/%
set converted=%converted:\=/%
echo.Converted to - %converted%
Sample tested output -
D:\Scripts>repl.bat E:\Server\htdocs\labs\php\testProject\test.php
Input was - E:\Server\htdocs\labs\php\testProject\test.php
Converted to - http://localhost/labs/php/testProject/test.php
Cheers, G