Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 22, 2013, 10:28 PM   #1
dancks
macrumors member
 
Join Date: Nov 2009
applescript differentiate file from folder

I am making a smart folder similar to a symbolic link that whenever a folder is created or something gets saved, its uploaded to my server. the folder structure is to match exactly what is on the server. Every folder will have this script attached:

Code:
-- https://discussions.apple.com/thread/1485146?start=0&tstart=0
-- https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/osascript.1.html
-- http://forums.macrumors.com/showthread.php?t=1089834
on run argv
	set FolderPath to current Folder
	set thename to name of FolderPath
	if thename = "place_on_server"
		try
			tell application "System Events"
				do shell script "HD:users:Jason Dancks:Desktop:place_on_server:uploadSO"&argv
			end tell
		end try
	else
		set thenext to name of container of FolderPath":alertscriptrev.scpt"
		try
			do script thenext&argv&thename
		end try
	end if
end run
on adding folder items to this_folder after receiving added_items
	set lastchar to 
	try
		tell application "System Events"
			if added_items --right here. I thought I would look for "/"
                                              --as the last character to see if folder or file
			do shell script "HD:users:Jason Dancks:Desktop:place_on_server:uploadSO"&"FILE"&this_folder&"/"&added_items
		end tell
	end try
end adding folder items to
I'm having problems with the last

the script grabs the name of the directory or file and recursively calls the same applescript attached to a containing folder up until it reaches the parent folder: place_on_server. Then it calls the shell script I'm using for uploads. I'm doing this because... I need the path, and I didn't think to just echo the path itself. whatever. learning experience. Problem is I have no idea how I would differentiate between a folder or a file in applescript. Any ideas?
dancks is offline   0 Reply With Quote
Old Jun 23, 2013, 10:35 PM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Remember that added_items is a list of aliases. Loop through your list and check the kind property of your item to see if it's a folder.
Attached Thumbnails
Click image for larger version

Name:	Picture 6.png
Views:	99
Size:	106.5 KB
ID:	419361  
__________________
Space Corps Directive 34124
kryten2 is offline   1 Reply With Quote
Old Jun 30, 2013, 08:34 PM   #3
dancks
Thread Starter
macrumors member
 
Join Date: Nov 2009
Better late than never. Thank you very much. I couldn't figure out how the recursion should work when the script is simply attached as a folder action and not present so I abandoned that and went to traditional path

so instead of ./myscript a b c d test.txt
its now
./myscript /users/me/Desktop/place_on_server/a/b/c/d/test.txt

but I still need to figure out the POSIX (I'm guessing that *nix) path.

so revised, script is:

Code:
-- https://discussions.apple.com/thread/1485146?start=0&tstart=0
-- https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/osascript.1.html
-- http://forums.macrumors.com/showthread.php?t=1089834
on adding folder items to this_folder after receiving added_items
	set FolderPath to POSIX path to this_folder
	set the_name to the name of added_items
	set isfile to kind of added_items
	tell application "System Events"
		try
			set check to the name of this_folder as string
			if check = "place_on_server"
				if isfile = "file"
					do shell script "HD:users:Jason Dancks:Desktop:place_on_server:uploadSOrev"&"F"&the_name
				else
					set FolderPath to path to added_items
					attach action to (alias FolderPath) using "HD:users:Jason Dancks:Desktop:place_on_server:alertscriptrev.scpt"
					do shell script "HD:users:Jason Dancks:Desktop:place_on_server:uploadSOrev"&"DIR"&the_name
				end if
			else
				if isfile = "file"
					do shell script "HD:users:Jason Dancks:Desktop:place_on_server:uploadSOrev"&"F"&FolderPath&the_name
				else
					set FolderPath to POSIX path to added_items
					do shell script "HD:users:Jason Dancks:Desktop:place_on_server:uploadSOrev"&"DIR"&FolderPath
					set FolderPath to path to added_items
					attach action to (alias FolderPath) using "HD:users:Jason Dancks:Desktop:place_on_server:alertscriptrev.scpt"
				end if
			end if
		end try
	end tell
end adding folder items to
dancks is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Tags
applescript, directory, folder, recursion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How to differentiate differentiate early 2009 MP from mid 2012? Caesar_091 Mac Pro 14 Jan 7, 2014 09:13 AM
I want to make AppleScript Create Folder DavidBlack Mac Programming 27 Mar 15, 2013 07:18 PM
iPhone: Anonymous folder and file in Downloads folder bun.bhay Jailbreaks and iOS Hacks 4 Sep 26, 2012 09:41 PM
Mac locks folder when it opens a file in that folder Tommy Yesterday Mac OS X Server, Xserve, and Networking 2 Sep 25, 2012 04:40 PM
How to differentiate ipad and iphone apps at mobile application folder yv.haranath iPad 0 Jun 20, 2012 12:27 PM

Forum Jump

All times are GMT -5. The time now is 11:35 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC