argv - getting the current working dir[Up to topic list]  [Home]

Who What
FiPa
07 Nov 2012, 04:06
argv - getting the current working dir
hi,
i try to make a "new file" menu and for that i have to know from where i am calling this menu.
this is working fine when i ctrl-click on a file (then i get the full file path), but its not working, when i click on empty space (on finder).
i've tried it with:
defaults write com.finderpop.finderpop useOSADoScriptFile -bool true

but this changes nothing.
in older versions it worked with following applescript:
Code:
on run argv
   do shell script "php -f /Users/.../Scripts/FinderPop/CreateFile.php -- "" & argv & "" txt"
end run


but now its not.
my checksum shell script is working fine:
Code:
cs=`md5 "$1"`
cs=${cs/*=}
terminal-notifier -message "$cs" -title "Checksum" -subtitle "$1"

cause i have to click on a file for that.

how can i get the working dir now (in the newest version)?

i couldnt understand this:
viewtopic.php?f=3&t=255&p=1136&hilit=argv

thanks for your support :)
turly
07 Nov 2012, 10:42
Re: argv - getting the current working dir
Is the script even called at all? If so, what is argv ?
A while back I changed the way scripts were called, maybe I broke something.
If you can use a shell script instead, then $PWD will be the current directory (ie the folder you clicked in.)

I'll look at this next time I'm at my Mac!
FiPa
09 Nov 2012, 08:28
Re: argv - getting the current working dir
hi,
when i right-click on the desktop and choose a shell script:
$PWD returns me the location of the shell script and
$1 returns me an empty string
instead of the finder-location (desktop-dir).

but...
when i right-click on a file on the desktop and choose a shell script:
$PWD returns the same (location of the shell script)
and $1 returns the location of the file (this should be correct).

so i only can get locations of files (when i right-click on them), but not of finder-directories (when i right-click on empty spaces).

argv is the parameter of an applescript, it's the same like $1 in shell scripts.

why i need the location when i click on empty spaces in the finder:
i want to create a menu item to create new (blank) files:
Bildschirmfoto 2012-11-09 um 08.27.14.PNG
Bildschirmfoto 2012-11-09 um 08.27.14.PNG (44.68 KiB) Viewed 4840 times


kind regards
turly
09 Nov 2012, 15:29
Re: argv - getting the current working dir
Umm, when I asked "what is argv", I meant "What is the value of argv" :-)

Anyway, it seems I should pass the current directory path if there is no item clicked on. I'll have a look !
FiPa
10 Nov 2012, 13:07
Re: argv - getting the current working dir
ah sorry, argv has the same value like $1 in shell (empty value when you rightclick on empty spaces, location of the file when you rightclick on files)

good luck and thank you :)
turly
21 Jan 2013, 08:27
Re: argv - getting the current working dir
This is fixed in 2.4.7 ... but you need to set a finderpop defaults pref to activate it as the behaviour is different. Alternatively rewrite your scripts to access shell vars FP_NARGS and FP_CLICKWIN (in addition to any argv values passed.)

  • When running shell scripts (and AppleScripts) we now have option to pass the window clicked on if there was no Finder selection. If you want this behaviour, you need to enable it via
    defaults write com.finderpop.finderpop passClickedFolderToScripts -bool true
    If there was a Finder selection, that will always be passed instead.
    Also set two environment vars which can be examined by scripts
    FP_NARGS to show how many items were in the Finder selection at the time of the control-click
    FP_CLICKWIN containing the path of the window clicked in (if applicable - unset when clicking in unused menubar)
  • Also fix a bug related to the above where I was forgetting "the window clicked in" too early.